aspose file tools*
The moose likes Servlets and the fly likes File reading from any path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "File reading from any path " Watch "File reading from any path " New topic
Author

File reading from any path

Kousik Majumder
Ranch Hand

Joined: Sep 30, 2007
Posts: 229
Hi all,

Can somebody tell me how can I read files from another directory/drive other than my application.

i.e my path of application in server = C:\deploy

I want to access the files from path = D:\Program Files\Java\rt.txt


Thanks in advance,

Kousik


Thanks in Advance,
Kousik
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Use java.io.File with an absolute path.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Syam Sathyan George
Ranch Hand

Joined: Apr 26, 2006
Posts: 64
If i understand your problem, you need to read a file(XML/property or Text) from within a servlet/webapplication, but the file is out side the projects root folder.

Possible answers.
1,Read using File, give absolute path to the file(eg "C:\")
This solution will make your web app to be system dependent(since C:\ maynot be present in a linux server), which is against java ideology of deploy/run anywhere!!.

2,Read using a file but find the relative path from inside the Servlet Context, and load it relatively, so your application works on any deployment machine.

TADA


Syam.Sathyan.George
(My boss is a Jewish carpenter)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File reading from any path