• Post Reply Bookmark Topic Watch Topic
  • New Topic

determine if file or directory in a web application  RSS feed

 
Larry Xu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!