File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

finding the exact path in a file system

 
baran tamer
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ,
How can i find the path of a file that is being viewed in a file system ?

thanks
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
File#getPath()?

http://java.sun.com/javase/6/docs/api/java/io/File.html
 
baran tamer
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply,

I have managed to do what i need by

ServletContext.getRealPath();
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17624
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic