struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephan Wiesner <>
Subject Re: Opening/reading a file from a Struts application...
Date Wed, 30 Jul 2003 05:06:39 GMT
You can load Properties files like this: in = baseClass.getResourceAsStream(fileName);
      Properties props = new Properties();

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.


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  
>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...
>To unsubscribe, e-mail:
>For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message