#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    I am running JServ on linux and having trouble reading and writing files. My code works fine from a regular java application. Is there some trick to doing this from a servlet?
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    Okay, so I'm that lame. hehe...

    My bad code was my problem. To anyone with this same question, here is some code that actually works:
    //////////////////////////
    //READING:
    try{
    fis = new FileInputStream(getFullPath());
    dis = new DataInputStream(fis);
    while( dis.available() != 0)
    { System.out.println(dis.readLine());}
    // I know, I know...
    // readline() is deprecated... : (
    dis.close();
    }catch(IOException e)
    { System.out.println(e.toString());}

    /////////////////////////////////////////
    // Write something
    FileOutputStream fos = null;
    PrintStream p = null;
    try{
    // Create a new file output stream
    fos = new FileOutputStream(getFullPath());
    // Create a print stream using your new output stream
    p = new PrintStream( fos );
    //Write something in the file
    p.println ("You are a freak!");
    // free up the stream.
    p.close();
    }catch(IOException e)
    {System.out.println("write file error" + e.toString());}

IMN logo majestic logo threadwatch logo seochat tools logo