You can load Properties files like this: java.io.InputStream in = baseClass.getResourceAsStream(fileName); Properties props = new Properties(); props.load(in);
I use this with my base classes, as the have to work outside my Tomcat, too, that's what base classes for, after all.
Have not tried but should work with other files as well.
Stephan
Davide Bruzzone wrote:
Greetings all...
I'm trying to load and read a text file (on the server's filesystem) from within a Struts application. I'd like to be able to put the file in the WEB-INF, or the WEB-INF/classes directory, but am having trouble finding the file (i.e. I'm having trouble obtaining the path that I need in order to open the file), and reading it...
Here's what my research has turned up:
// Something like this will return an InputStream. This is fine for
properties files
// since you can load a properties file by passing an InputStream to the
load method
// on a Properties object Thread.currentThread().getContextClassLoader().getResourceAsStream("my.p
roperties");
The problem with this is that the methods that I'm using to read the contents of files takes either a string that represents the file name, or a File object... The methods then calculate the file's length, read the file into an array of bytes, and return the contents of the array in various forms (i.e. An array of bytes, a string, etc.).
Does anyone have any suggestions about how best to go about doing this (I could change the methods that read the contents of files into strings, but I'm not sure exactly how to go about doing this).
Any help would be greatly appreciated...
Cheers...
Dave
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]