This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 60816
    
  65

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: 1016
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
Unable to access files outside Webapp directory in tomcat
How would you design this??
context.xml + Help Needed
Stroring Word Documents into MYSQL Database
File Management