Bufferedwriter works, but file empty?

廉价感情. 提交于 2019-11-28 12:51:13

You never flush the buffer, or close the BufferedWriter.

After the for loop, make the following calls:

buff.flush();
buff.close();

Even with other resources, closing them when done is a good idea.

You have to close() the stream after use.
Call buff.close() after write loop; BufferedWriter will flush data to file at close.

Though the question is answered . I would like to add how buffer works.

whenever you try to write to a file using buffer,whatever you write gets added to the buffer. When the buffer is full the contents are written to the file . This way we are reducing the number of hits to the hard-drive hence improving the efficency.

If we want to forcefully write to a file without the buffer getting full , we use flush() method.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!