Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

InputStream using file at relative path

807588Jul 9 2009 — edited Jul 9 2009
I am using a servlet to open a file stream for a file located in /WEB-INF/files

When I use the following code I get an error stating that a file does not exist in the location:
String fileLocation = "files/myFile.dat";
FileInputStream fstream = new FileInputStream(fileLocation);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null)   {
      // process file line-by-line
}
 in.close();
The absolute path to the file is: C:/NetBeansProjects/myApp/web/WEB-INF/files/myFile.dat

How can I refer to documents from a servlet without getting an error?

I am using SpringFramework MVC if that matters to this issue.

Regards...
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 6 2009
Added on Jul 9 2009
2 comments
722 views