Where should I put .txt file(s) to be accessed by a bean so that the results are passed to a JSP file? I am getting an "File Not Found" exception when I put them in the directory where my bean resides.

Larry LeFever

Try out.println(System.getProperty("user.dir")); that should show you what the current working directory is; it should be, I believe, the directory that was current working directory when the given servlet engine's JVM was started (i.e., inherited from the shell used in order to start it); that, in turn, is, I believe, the directory relative to which relative paths are interpreted by the File class; however, using paths explicitly relative to that path would require hard-coding paths (or path-elements)into compiled code (bad in terms of configuration-options). I just started using an alternative:

String path = java.util.ResourceBundle.getBundle("[properties-filename-without-ext]").getString("[e.g., txtFilePath]"); 
File x = new File(path + fname);
 ("fname" presumably coming from use of File.list(), typically involving an array of fnames).
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact