I am using FileWriter and I have noticed strange behavior.
I buffer my collection myself and every x rows I use
IOUtils.writelines(myList,"\n", writer );
It doesnt write to the file. I continue to call it with more lines and only after it is very full it writes to the file.
Does it use a buffer? I cant find it in its documentation.
The second sentence of the
FileWriterclass overview says:(My emphasis)
So clearly it’s buffered (unless the default byte-buffer size is zero and they’re being really odd with their phrasing).
I suspect it’s just using an
OutputStreamWriteron aFileOutputStream. Looking atOutputStreamWriter:(My emphasis)
If you want to ensure that various buffers at various levels are flushed, to the extent you can, look at using the
flushmethod.