wood burning stoves 2.0
The moose likes Servlets and the fly likes problem while reading in servlet..! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem while reading in servlet..!" Watch "problem while reading in servlet..!" New topic

problem while reading in servlet..!

Jack Doson

Joined: Oct 02, 2008
Posts: 9
Iam developing a web Application named cabworker

in that application i created "media" directory and i placed a text file called dates.txt in that directory.

now iam reading that file inside a servlet like this.

FileReader fw=new FileReader("media/dates.txt");

here it is giving exception like file specified not found(but it is compiling properly)..!

when i tried to read like

FileReader fw=new FileReader("/media/dates.txt");
still it is same exception..!

please help me in this regard.!

Jack Dososn..!
Satish Chilukuri
Ranch Hand

Joined: Jun 23, 2005
Posts: 266
FileReader takes in an file system path. In your case it is looking for the file /media/dates.txt on your file system and not in your web application. You can use the ServletContext's getRealPath() to convert a web application path to the file system path and then pass it to FileReader.
I agree. Here's the link: http://aspose.com/file-tools
subject: problem while reading in servlet..!
It's not a secret anymore!