my dog learned polymorphism*
The moose likes JSF and the fly likes finding the exact path in a file system Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "finding the exact path in a file system" Watch "finding the exact path in a file system" New topic
Author

finding the exact path in a file system

baran tamer
Ranch Hand

Joined: Jan 22, 2009
Posts: 33
Hello ,
How can i find the path of a file that is being viewed in a file system ?

thanks
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
File#getPath()?

http://java.sun.com/javase/6/docs/api/java/io/File.html
baran tamer
Ranch Hand

Joined: Jan 22, 2009
Posts: 33
Thanks for the reply,

I have managed to do what i need by

ServletContext.getRealPath();
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
That is to be used to convert a relative web path to an absolute filesystem path. Your initial question didn't make that clear.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15957
    
  19

Look closely at the JavaDocs. getRealPath will return null if the "file" isn't really a file. For example, when it's inside of a WAR file.

It's very bad practice to read or write to files inside the web application deployment. First, because they may not be files, as I just said. Secondly, because they can get accidentally wiped out when the application is updated.

If an app needs to write files, use an external directory (you can use JNDI to configure a path, if you'd rather not hard-code it in the app). If you need to read constant files and it's convenient to keep them as part of the deployed WAR, use the resource utilities to access the data.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: finding the exact path in a file system
 
Similar Threads
servlet initializatoin parameter to get relative path and file name
InputStream reference
including content from webserver in JSP
Problem in using java to Store 1GB+ files in a MySQL database
get image from database