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


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 (;
      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!

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
and if you're doing an upload the file should be read from the request, and not from disk.
francocaroAuthor Commented:
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?

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.