Member Avatar for mehnihma

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();
                    }

Recommended Answers

All 3 Replies

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?

Member Avatar for mehnihma

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);
              }
Member Avatar for mehnihma

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.