wood burning stoves
The moose likes JSP and the fly likes Access files in web application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Access files in web application" Watch "Access files in web application" New topic

Access files in web application

Lalit mishra
Ranch Hand

Joined: Sep 01, 2005
Posts: 100
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

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63837

plz help its urgent

Please read this to see why adding statement like this are actually counter-productive. Also please spell "please" as please.

[Asking smart questions] [About Bear] [Books by Bear]
Stefan Evans

Joined: Jul 06, 2005
Posts: 1580
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

Joined: Jun 27, 2006
Posts: 1
// 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 );
I agree. Here's the link: http://aspose.com/file-tools
subject: Access files in web application
jQuery in Action, 3rd edition