• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem while reading in servlet..!

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.!
 
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic