#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2001
    Location
    Australia
    Posts
    69
    Rep Power
    13

    Servlet reading a file...


    Hello,

    How do I get a servlet to read a file? I need to read a .txt file and store its contents in a String variable. However, no matter where I put the .txt file, the servlet never seems to find it.

    Thanks
  2. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Here's the class to use:
    http://java.sun.com/j2se/1.3/docs/ap...ileReader.html

    I'd suggest wrapping it in a BufferedReader, like
    Code:
    BufferedReader in  = new BufferedReader(new FileReader("foo.in"));
    then you can use the readLine method from BufferedReader.
  4. #3
  5. No Profile Picture
    Database Expert
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Posts
    20
    Rep Power
    0
    Servlets read files just as any other Java application does. You will need to import the java.io.* package.

IMN logo majestic logo threadwatch logo seochat tools logo