• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing a folder within a web application...

 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
InputStream is =
ClassLoader.getSystemResourceAsStream("./files/" +fileName);
bufferedReader = new BufferedReader(new InputStreamReader(is));

This works fine for reading..but what about writing...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic