Solved

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

Posted on 2004-10-28
367 Views
Last Modified: 2008-03-06
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
Question by:francocaro
    3 Comments
     
    LVL 8

    Accepted Solution

    by:
    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
     
    LVL 92

    Assisted Solution

    by:objects
    and if you're doing an upload the file should be read from the request, and not from disk.
    0
     

    Author Comment

    by:francocaro
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: MongoDB Object-Document Mapper for NodeJS

    NodeJS (JavaScript on the server) is awesome, but some developers get confused about NoSQL when it comes to working in Node with MongoDB (NoSQL database). Do you need a better explanation of how to use Node.js with MongoDB? The most popular choice is the Mongoose library.

    For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    933 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now