aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Access files in web application" Watch "Access files in web application" New topic
Author

Access files in web application

Lalit mishra
Ranch Hand

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

Joined: Jan 10, 2002
Posts: 61424
    
  67

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] [Bear's FrontMan] [About Bear] [Books by Bear]
Stefan Evans
Bartender

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

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