RandomQuestion
RandomQuestion

Reputation: 6998

Performance of FileUtils.write from Apache Commons - Java

I have gone through the javadoc but I could't find anything.Does it buffer data internally? If yes, since there is no close/flush operation, how does it make sure all data has been written. If it does not buffer, Does it go to disk everytime call is made?

http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html#write(java.io.File, java.lang.CharSequence, java.nio.charset.Charset, boolean)

I looked at source code here, http://grepcode.com/file/repo1.maven.org/maven2/commons-io/commons-io/2.4/org/apache/commons/io/FileUtils.java#FileUtils.openOutputStream%28java.io.File%2Cboolean%29 and it does not seem to do any buffering. It opens a stream every time.

Upvotes: 0

Views: 2686

Answers (1)

William Morrison
William Morrison

Reputation: 11006

From looking at the source, a new stream is created, the data is written out, and then the stream is closed.

Here's the link to the source I used to determine this. Eventually writeStringToFile is called when you call write.

This makes sense as its a static method which returns nothing.

So, it doesn't buffer data internally. Every time you call write data will be written to the file.

Upvotes: 5

Related Questions