aspose file tools*
The moose likes Beginning Java and the fly likes determine if file or directory in a web application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "determine if file or directory in a web application" Watch "determine if file or directory in a web application" New topic
Author

determine if file or directory in a web application

Larry Xu
Greenhorn

Joined: Sep 19, 2005
Posts: 11
hi I have a web application hosted using tomcat.

here's a simple layout of my structure
-src
- file A
- directory A
- file B
- file C
-build
-WebContent
- META-INF
- WEB-INF


my question is how do i determine if "file A" is a file or a directory.
if I do:
File file = new File("file A");
a file will be created in a different directory on my local harddrive, I guess what I am trying to say is how can I get to a file under my src directory.

thanks!



I am so frustrated...
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

A File is just "An abstract representation of file and directory pathnames." Creating a new File object does not create a new file.

If you're trying to determine whether something under SRC is a directory, here's a basic approach: Create a File object to represent the SRC directory by passing the SRC path to the File constructor. Then call listFiles() on that File object to get a File array representing all of the files and directories in SRC. Then iterate through this array, calling getName() to get the names, and isDirectory() to determine whether these represent directories.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: determine if file or directory in a web application