| Author |
Reading files
|
manjit singh thakurratan
Greenhorn
Joined: Dec 23, 2009
Posts: 10
|
|
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
internet detective
Marshal
Joined: May 26, 2003
Posts: 26173
|
|
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.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
manjit singh thakurratan
Greenhorn
Joined: Dec 23, 2009
Posts: 10
|
|
Hi could you please tell me more in detail.....!
I cud not understand with just a method name!
|
 |
 |
|
|
subject: Reading files
|
|
|