• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access files in web application

 
Lalit mishra
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in my web application i have some txt files how to programatically access those files . ie how to get there relative and actual path???

Does any one have sample code....

plz help its urgent


Thanks
Lalit
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
plz help its urgent


Please read this to see why adding statement like this are actually counter-productive. Also please spell "please" as please.
 
Stefan Evans
Bartender
Posts: 1691
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You access the files with the standard java.io package.

For help in converting from website-relative path to an actual location on disk, you can use the methods of ServletContext.

- getRealPath(String) - takes a website relative path, and returns you a real location on disk
- getResourceAsStream(String) - takes a website relative path, and returns an input stream to that resource.
 
Richard Barton
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
// assumes you're in a servlet
ServletContext ctx = getServletContext();

// resource is a filename accessible inside the servlet context
// which could also be in a JAR
ctx.getResourceAsStream( resource );
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic