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 Android Security Essentials Live Lessons this week in the Android 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

determine if file or directory in a web application

Larry Xu

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

here's a simple layout of my structure
- file A
- directory A
- file B
- file C

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.


I am so frustrated...
marc weber

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
I agree. Here's the link: http://aspose.com/file-tools
subject: determine if file or directory in a web application
Similar Threads
Regarding TLD Location
Writing to a file through Servlet
Confusion Regarding where to put jsp in Web-application.
Log4j not complaining but not printing anything too
Problem in Struts : Error 404 : servlet action as unavailable