Skip to content

Instantly share code, notes, and snippets.

@nein37
Created August 14, 2014 15:25
Show Gist options
  • Save nein37/d6c8de7e66b763685339 to your computer and use it in GitHub Desktop.
Save nein37/d6c8de7e66b763685339 to your computer and use it in GitHub Desktop.
安全にファイルを操作する ref: http://qiita.com/nein37/items/f50ab4fd39c3fdb8498a
AtomicFile atomicFile = new AtomicFile(getFileStreamPath(FILENAME));
FileOutputStream fos = null;
try {
// 書き込み開始
fos = atomicFile.startWrite();
fos.write(...);
// 書き込み成功
atomicFile.finishWrite(fos);
} catch (IOException ex) {
// 書き込み失敗
atomicFile.failWrite(fos);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment