Hi, One idea would be to search the archives for this question is asked very frequently. Frequently enough that we put it (or a close relation thereof) in our FAQ: http://jakarta.apache.org/tomcat/faq/misc.html#getResourceAsStream.
In short, don't depend on the File I/O API from a Servlet Container. Use either ServletContext#getResource or Class#getResource. The File I/O API, beyond breaking in packed WAR files, is sensitive to the Current Working Directory (CWD), which is defined differently in different operating systems, making your application far from portable. Yoav Shapira Millennium Research Informatics >-----Original Message----- >From: Julie McCabe [mailto:[EMAIL PROTECTED] >Sent: Tuesday, May 25, 2004 3:58 AM >To: [EMAIL PROTECTED] >Subject: Inconsistent path to files > >Hello, > >My setup is Tomcat 4.1.27, Java 1.4.2_02, Red Hat Linux 9.0. > >I have a JSP located in the webapps directory I would like it to read a >file >in the WEB-INF directory using a custom tag, eg, > >File f = new File("WEB-INF/fileToRead.txt"); > >depending on which directory I start tomcat from the file will be located >on >not - if I start tomcat from the $CATALINA_HOME directory it will work but >if >I start tomcat from $CATALINA_HOME/webapps/webApp directory it will not >pick >up the file because the location is wrong! I thought the code in the JSP >should work regardless of which directory tomcat is started from. > >In addition, I have noticed the behaviour of the > ><input type="file" is incorrect too > >In the JSP with this tag, I am able to browse to the correct file but when >the >upload is attempted I get a FileNotFoundException because it is looking for >$CATALINA_HOME/fileToUpload.txt - it ignores the path selected. > >I am guessing this is a classpath problem or an environment variable that >is >set when tomcat is started - I would appreciate any ideas on this. > >Thanks, >Julie McCabe. > >--------------------------------------------------------------------- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
