Note that there are some explanatory texts on larger screens.

plurals
  1. POext4/fsync situation unclear in Android (Java)
    primarykey
    data
    text
    <p>Tim Bray's article <a href="http://android-developers.blogspot.com/2010/12/saving-data-safely.html" rel="noreferrer">"Saving Data Safely"</a> left me with open questions. Today, it's over a month old and I haven't seen any follow-up on it, so I decided to address the topic here.</p> <p>One point of the article is that FileDescriptor.sync() should be called to be on the safe side when using FileOutputStream. At first, I was very irritated, because I never have seen any Java code doing a sync during the 12 years I do Java. Especially since coping with files is a pretty basic thing. Also, the standard JavaDoc of FileOutputStream never hinted at syncing (Java 1.0 - 6). After some research, I figured ext4 may actually be the first mainstream file system requiring syncing. (Are there other file systems where explicit syncing is advised?)</p> <p>I appreciate some general thoughts on the matter, but I also have some specific questions:</p> <ol> <li>When will Android do the sync to the file system? This could be periodic and additionally based on life cycle events (e.g. an app's process goes to the background).</li> <li>Does FileDescriptor.sync() take care of syncing the meta data? That is syncing the directory of the changed file. Compare to FileChannel.force().</li> <li>Usually, one does not directly write into the FileOutputStream. Here's my solution (do you agree?): <code><pre> FileOutputStream fileOut = ctx.openFileOutput(file, Context.MODE_PRIVATE); BufferedOutputStream out = new BufferedOutputStream(fileOut); try { out.write(something); out.flush(); fileOut.getFD().sync(); } finally { out.close(); } </pre></code></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload