Simple question regarding using FileReader in a Servlet
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   dan_f
Posted On:   Sunday, April 18, 2004 08:46 AM

I have a Servlet that attempts to load a file into a BufferedReader. The problem is the statement:

final BufferedReader tFile = new BufferedReader(new FileReader("a://file.txt"));

Whilst this statement did work in a java program on a standalone machine the Servlet is unable to locate the file. I simply need to load this file from any location not specifically an A: drive.


Any suggestions would be much appreciated.

Cheers

Re: Simple question regarding using FileReader in a Servlet

Posted By:   sushil_srivastava  
Posted On:   Friday, April 30, 2004 06:35 AM

It could be a very simple case of the machine on which you are trying to run the servlet not having access to the file which your application had.

Re: Simple question regarding using FileReader in a Servlet

Posted By:   Sean_Owen  
Posted On:   Monday, April 19, 2004 12:56 PM

Shouldn't this be "a:\file.txt"? See the javadoc for java.io.File. Not sure if that is the problem or not. Of course, verify that there is actually a file at a:file.txt!

You can't say "load file.txt, wherever it is" since that is ambiguous, but you could make the location of the file an environment property in your web application, and look up its location here, instead of hard-coding a location.

You might also consider packaging the file with the web archive and accessing it as a resource, if that is an option for you.
About | Sitemap | Contact