aspose file tools
The moose likes JSP and the fly likes Access files in web application Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSP
Reply 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: 56528
    
  14

plz help its urgent


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


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1008
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
 
Similar Threads
context.xml + Help Needed
How would you design this??
File Management
Stroring Word Documents into MYSQL Database
Unable to access files outside Webapp directory in tomcat