Error in reading from a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • radhikams
    New Member
    • Jan 2008
    • 49

    Error in reading from a file

    hi
    I have written a code for writing the data of a column from database into a file
    and again reading that file and displaying.

    Im writing into an .html file....Now the problem is im getting the output but that output is followed by an error.....

    This is the output
    -----------------------------
    A large number of processes are available, and can be applied to an input or a group of inputs. These processes can be chained ogether so that the output from one process is used as an input to another process. In this manner multiple processes may be applied to an input .Error 500: Server caught unhandled exception from servlet [JSP 1.2 Processor]: getCompressingO utputStream() has already been called

    Im not able to find wheres the mistake....Here is the code related to it

    [CODE=Java]String strPath="\\\\en ggsw-061\public\\LLD atabase\\sugges tions\\textfile 1.html";
    response.setCon tentType("APPLI CATION/OCTET-STREAM");
    //writing into a file
    File f=new File(strPath);
    FileOutputStrea m fop=new FileOutputStrea m(f);
    {
    if(f.exists())
    {
    String struggestion=cL essonsLearntSea rchActionForm.g etSuggestions() ;
    fop.write(strSu ggestion.getByt es());
    fop.flush();
    fop.close();
    }
    else{
    some error message
    }
    }
    //reading the file
    FileInputStream fileIn = new FileInputStream (f);
    OutputStream out = response.getOut putStream();
    {
    byte[] buffer = new byte[2048];
    int bytesRead = fileIn.read(buf fer);
    while (bytesRead >= 0) {
    if (bytesRead > 0)
    out.write(buffe r, 0, bytesRead); bytesRead = fileIn.read(buf fer);
    }
    out.flush();
    out.close();
    fileIn.close();
    }
    [/CODE]
    Thanks
    Last edited by BigDaddyLH; Feb 11 '08, 04:20 PM. Reason: added ciode tags
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Use a PrintWriter for writing the data. It's text isn't it?

    Comment

    • BigDaddyLH
      Recognized Expert Top Contributor
      • Dec 2007
      • 1216

      #3
      Please enclose your posted code in [code] tags (See How to Ask a Question).

      This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

      Please use [code] tags in future.

      MODERATOR

      Comment

      • radhikams
        New Member
        • Jan 2008
        • 49

        #4
        Originally posted by r035198x
        Use a PrintWriter for writing the data. It's text isn't it?
        Hi
        This helped me fine...Now there is no such error... everything is working fine..

        Thank You

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by radhikams
          Hi
          This helped me fine...Now there is no such error... everything is working fine..

          Thank You
          The right tool for the right job ...

          Comment

          Working...