• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

File reading from any path

 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use java.io.File with an absolute path.
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic