BufferedWriter not writing everything to its output file

前端 未结 9 1932
悲哀的现实
悲哀的现实 2020-11-22 03:35

I have a Java program that reads some text from a file, line by line, and writes new text to an output file. But not all the text I write to my BufferedWriter a

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 04:19

    According to documentation it is no use calling flush() method. If you intent to use FileWriter then flush() would help you out.

    Basically in this case, you just need to close, BufferedWriter.close() only. This will flush the remainder of your data.

    create finally block and put the close method inside so that it will put all data without missing.

     finally {
        out.close();
        }
    

提交回复
热议问题