[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Problem reading file uploaded from JSP page (tried FileReader and InputStreamReader)

Posted on 2004-10-28
Medium Priority
Last Modified: 2008-03-06

I am developing a file upload utility for a web application using JSP/JS/Java.
I pass the full path of the file to be uploaded to my Java code but I am having a problem actually reading the file.

What is strange is that my code works exactly as I want it to on my desktop using WebSphere but after moving the code to our development box, I get the error "No such file or directory" (and I know the file is there) when it gets to the FileReader . I tried using InputStreamReader instead but I get the same error.

Has anybody come across this before? Do you have any suggestions for me?

Here is a part of my code:
public void perform(HttpServletRequest request) throws Exception {
   String filename = request.getParameter("upload");
   //filename now contains the full path of the file i.e. C:\Data\Upload\samplefile.csv
   try {
      FileReader file1 = new FileReader (filename);  //I get an error on this line
      BufferedReader inputFile = new BufferedReader(file1);
      dataLine = inputFile.readLine ();

//ALSO TRIED below code to see if I could read just one character
/*       FileInputStream fis = new FileInputStream(filename);
      InputStreamReader isr = new InputStreamReader(fis);
      System.out.println (isr.read());
      StreamTokenizer st = new StreamTokenizer(isr);
      System.out.println (st.nextToken());

Let me know if you need any more information from me!
I really appreciate any help and suggestions!

Question by:francocaro
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

kiranhk earned 1600 total points
ID: 12439570
you are trying to read the file which is on the client side. The path is valid only on the client machine. it worked on ur machine becoz the client and the server was running on the same machine and the path was valid.
do check out this



hope this helps
LVL 92

Assisted Solution

objects earned 400 total points
ID: 12439645
and if you're doing an upload the file should be read from the request, and not from disk.

Author Comment

ID: 12440642
Thank you both for your help!

1. how do I read a file from the request?
2. should I post another question for this so that you can receive points?


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question