3

I have two linkedlists A1 and A2, both contain very long strings. I want to paste these strings for both linkedlists in one file i am using this function:

 private static void append(LinkedList A1, LinkedList A2) {

   try{
BufferedWriter outC = new BufferedWriter(new FileWriter(new File(file), true));

            for(int i=0;i<A1.size();i++){

                String c = (String)A1.get(i);
                outC.write(c+"\n");               
                }


                for(int i=0;i<A2.size();i++){

                String c = (String)A2.get(i);
                outC.write(c+"\n");               
                }
              } catch (Exception e) {
                e.printStackTrace();
}


            }

What I get in the output file is only 60 out of 80 strings from the first linkedlist and nothing from the second linkedlist ! what is the cause of this problem ? is it because the tsrings are too long ?

infoSyStem
  • 145
  • 1
  • 2
  • 14

1 Answers1

3

Try and flush() then close() the BufferedWriter (and also close the FileWriter while you're at it).

fge
  • 119,121
  • 33
  • 254
  • 329