-----Original Message----- From: Jarnot Voytek Contr AU HQ/SC Sent: Friday, June 27, 2003 11:53 AM To: 'Struts Users Mailing List' Subject: RE: getting a file path to /WEB-INF from a HttpSession
try request.getSession(false).getServletContext().getRealPath("/WEB-INF/...")) or, in an action you could do getServlet().getServletContext().getRealPath("/WEB-INF/..."); -- Voytek Jarnot Quidquid latine dictum sit, altum viditur. > -----Original Message----- > From: Davide Bruzzone [mailto:[EMAIL PROTECTED] > Sent: Tuesday, July 29, 2003 12:58 PM > To: Struts Users Mailing List > Subject: Opening/reading a file from a Struts application... > > > 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().getResourceAsSt > ream("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]