Tomcat Server

bacon333

Senior member
Mar 12, 2003
524
0
0
This should be really simple but I can't seem to get it to work.

All I'm trying to do is read a text file on the tomcat server.

frmCW = new BufferedReader(new FileReader(new File("common.txt")));

I am hosting tomcat 5 locally. The file can be read if I specify "c:\java\common.txt" but if i specify a relative path it looks at c:\windows\system32 for some reason. Has anyone ever ran into this problem?

I've tried getCanonicalpath , getAbsolutePath, everything and still no luck.

I have tried the suggestion here: http://forum.java.sun.com/thread.jspa?threadID=616327&messageID=3431287. It worked for the user but I'm not sure how to init the servletconfig().
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Well, the notion of a working directory doesn't really make a whole lot of sense in a java webapp. Manipulating files is also generally not a good idea, since it's not threadsafe. If all you're trying to do is read a file off of disk the recomended way would be to put in your classpath and use Class.getResourceAsStream() to pick it up. That way you're completely filesystem independent.