• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading files

 
manjit singh thakurratan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34974
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Hi could you please tell me more in detail.....!

I cud not understand with just a method name!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic