Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

Question: I'm trying to read a file from the jsp file on the server. It works fi

JavaFAQ Home » JSP, Servlets Go to all tips in JSP, Servlets


Bookmark and Share

Question: I'm trying to read a file from the jsp file on the server. It works fine when I try to read the same file on my PC with the following statement:

FileReader f = new FileReader("d: empa.txt");
BufferedReader fi = new BufferedReader(f);

However, when I run the same JSP file with the same statement on the server, I get the exception saying that the file cannot be found...
I am sure that the file file is in the same directory as the JSP file that tries to open it.

FileReader f = new FileReader("a.txt");
BufferedReader fi = new BufferedReader(f);


Here is the error when the above is executed by JSP on the server:

500 Internal Exception
error = java.io.FileNotFoundException: a.txt

Answer: The JSP is not in the same directory as the text file. The JSP is stored in a default location within the server itself because it is compiled to a servlet.
You have two options: 1. Find this location and put your text file there,
or
2. Provide the full path to file reader the full path or give it a relative path (the best choice, since the code will be portable.
***************************************
Our older tips: March 22, 2001 - Oktober 21, 2002 read here.
All published and not published on site tips you can find here


 Printer Friendly Page  Printer Friendly Page
 Send to a Friend  Send to a Friend

.. Bookmark and Share

Search here again if you need more info!
Custom Search



Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy