aspose file tools*
The moose likes JSP and the fly likes Accessing a folder within a web application... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Accessing a folder within a web application..." Watch "Accessing a folder within a web application..." New topic
Author

Accessing a folder within a web application...

A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Hi,

In my web application,

I have to have a folder where i should store some intermediate files..

Web_context/files/*.*

In the code how should i specify the path..

Because...i tried....it in tomcat and i had to specify it as..

File file=new File("../webapp/Web_context/files/xyz.txt");

But i want to speicify it from the web context and not from the appserver ..
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

But i want to speicify it from the web context and not from the appserver ..

You've almost got the answer Look into ServletContext. You will find methods like getResource and getResourceAsStream to access resources in your web application.


[My Blog]
All roads lead to JavaRanch
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
But my class is a utility class..which gets called from different classes..in the app and the call to this doesnt have the servlet context passed to it..

Regards
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
InputStream is =
ClassLoader.getSystemResourceAsStream("./files/" +fileName);
bufferedReader = new BufferedReader(new InputStreamReader(is));

This works fine for reading..but what about writing...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing a folder within a web application...