Link to home
Start Free TrialLog in
Avatar of jtcy
jtcy

asked on

FileReader & PrintWriter

Can a FileReader object get written twice? I just create a file using PrintWriter with a FileReader object as its argument. Result of that is a file created. Then i need to write something to that file which just created. So i create a printWriter object again with that FileReader object. But that doesnt work. Can someone help?

public void writeFile(FileReader in) throws java.io.IOException
    {
          
          PrintWriter out = new PrintWriter(writer);
          
          BufferedReader inFile = new BufferedReader(in);
          String line =null;
         
         int j = 1;
         while ((line = inFile.readLine())!= null)
          {
                 out.println(j+ " :   " + line);
                 j++;
           }
           out.println("");
           out.println("");
          
          inFile.close();
            out.close();

    }

so I first call
writeFile(inFile);
then i do:

PrintWriter err = new PrintWriter(parser.writer);
            // add any error messages to the listing file...

                for (int i=0; i<parser.errors.size(); i++)
                 {
                       String k = (String)parser.errors.get(i);
                       err.println(k);
                 }
               
                err.close();

the problem is nothing being added to the file which just created.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
8-)