I'm having a problem opening a file using the BufferedReader and I'd post the code except for the fact that it's 14 miles long. Basically, I am using a
Servlet and
JSP through
Tomcat 5.0, and I am trying to get my Servlet to open a file on the server side and parse it. Here is the line I'm using:
try
{
BufferedReader inFile = new BufferedReader(new FileReader("Courses.txt"));
}
catch(FileNotFoundException fnfe)
{
System.out.println("File not found exception:\n" + fnfe.getMessage());
}
That sniplet of code, as well as Courses.txt, is located in a server-side Servlet in the directory of:
"C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\myTestApp\WEB-INF\classes\CoursePackage"
The
JAVA file is indeed part of a package (CouresPackage) and is being used by Tomcat. For some reason, everytime that code executes, the FileNotFoundException is thrown and caught, and the following message is given:
Courses.txt (The system cannot find the file specified)
The weird part is, if I change the parameter from "Courses.txt" to "C:\\Courses.txt" (and place Courses.txt directly on the C drive), the FileNotFoundException is never thrown and all works fine. However, I want to use a relative file path. Consequently, I have a copy of Courses.txt in nearly every directly under Tomcat, but still the file is never found when the program executes.
Where is JAVA/Tomcat looking to find this file??