• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Reading files

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I added a txt file in my package with some properties like
username = xxxx
password = xxxx
dbname = xxxx

When i start the server my servlet will open this file to get the properties.

The problem is that though the servlet and the file are in the same package, the file cannot be found.

When i write the following code

String fileName = "App.txt";
FileReader reader = new FileReader(fileName);

The reader returns a filenotfound exception

I am using eclipse and the directory the file being looked is something like this i:\eclipse\App.txt . This is the directory where I installed eclipse

It is searching for the file in the installation directory while I have placed the file in the current package.

Can some one help me

the files are as follows

com.example.servlet.Reader.java
com.example.servlet.App.txt

REgards
Manjit Singh
 
author & internet detective
Posts: 41250
849
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Manjit,
The classpath of Tomcat (or whatever you are using to run your servlet) wouldn't start from wherever the servlet is. It could start from WEB-INF/classes. I usually use getResourceAsStream() and pass the package name of the file to it.
 
manjit singh thakurratan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi could you please tell me more in detail.....!

I cud not understand with just a method name!
 
Wanna see my flashlight? How about this tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic