• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 428
  • Last Modified:

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

Hello!

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!

-C
0
francocaro
Asked:
francocaro
2 Solutions
 
kiranhkCommented:
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

http://www.jguru.com/faq/view.jsp?EID=160

http://www.servlets.com/cos/

hope this helps
0
 
objectsCommented:
and if you're doing an upload the file should be read from the request, and not from disk.
0
 
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?

-C
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now