|
> From: Joel R. Cochran
>
> I have no trouble getting my servlets to use classes in my
> packages, but one
> of the classes is giving me fits. In one of the packages, I have a class
> that reads a text file and outputs the text, line by line, to a web page.
> The problem is that no matter where I put the text file the class throws
> this exception: "FileNotFoundException:No such path or directory".
>
> I do this in a stand alone Swing application with no trouble. In
> that case,
> you must put the text file in the same directory as the class
> that calls the
> package. In this case that would be the "classes" directory.
>
> I have placed the file in myApp, WEB-INF, classes, and the package
> directory, but it is never found.
>
> I have tried accessing it using filename, /filename, myApp/filename, and
> /myApp/filename.
Try the ServerRoot directive in the http.conf file in your Apache setup (in
the IFS in folder QIBM/HTTPA/conf). That usually does the trick. For
standalone Tomcat, it's a little different.
If you can't wade through the configuration files, you can use the File
class to empirically determine what your root directory is. Just run the
following code in a servlet:
String[] files = { "file", "/slashfile", "./dotfile", "/./slashdotfile"
};
out.println("<H4>File paths</H4>");
out.println("<table border=4>");
out.println("
<tr><th>AbsoluteFile</th><th>AbsolutePath</th><th>CanonicalFile</th><th>Cano
nicalPath</th></tr>");
try {
for (int i = 0; i < files.length; i++)
{
File file = new File(files[i]);
out.println(" <tr><td>" +
file.getAbsoluteFile() + "</td><td>" +
file.getAbsolutePath() + "</td><td>" +
file.getCanonicalFile() + "</td><td>" +
file.getCanonicalPath() + "</td></tr>");
}
} catch (Exception e1) {}
out.println("</table>");
It will print out a table of the paths and files for various syntaxes of
file prefixes.
Joe
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.