I have problem , I only get program to write the frist line but how to write the whole string?
When I print that string I get correct ouput? It has 10 lines

     String fileName = "System.err";
                 File newFile = new File(fileName);



                 try {



                    if (newFile.exists()) {
                       FileWriter fos = new FileWriter(newFile);
                       fos.write(strLine);
                       fos.close();
                                System.out.flush();

                    }





                 } 
                    catch( IOException ioe ) {
                       ioe.printStackTrace();
                    }

Edited 4 Years Ago by ~s.o.s~: Edit title

write the frist line but how to write the whole string?
What do you mean by a line and a String? Can you define what the difference is between those two terms?

What do you use to view the contents of the output file?

I am using while to read from the file and to input lines into the string , it prints correct but it writes just the laste line

 catch (NumberFormatException n) {

                 //String newLine = strLine;



                 System.out.println("Error found in: " + strLine + "\n Offending item is: " + fieldCounter);

                // write file to txt System.err


                 fstream = new FileWriter("System.err");
                 outerror = new BufferedWriter(fstream);

                 //Writer outerror = new BufferedWriter(new FileWriter("System.err"));
                 fstream.write("Error found in: " + strLine + "\n Offending item is: " + fieldCounter);
                //Close the output stream
                 outerror.close();
                 //fstream.flush();



                // writeFile(strLine);


              }

              catch (Exception e) {
                 System.out.println("Exception while reading csv file: " + e);
              }

Edited 4 Years Ago by mehnihma: wrong wouote 22

I got it, i needed to declare it in main and close it out while loop :D

This question has already been answered. Start a new discussion instead.