您的位置:首页 > 移动开发 > Android开发

android in practice_Making sure files are saved with sync

2013-01-04 16:32 489 查看
You need to guarantee that file data is written to disk immediately, regardless of the filesystem in use and the platform version.
Syncing ensures that the buffer catches up with the physical disk.
You can get a FileDescriptor reference from FileOutputStream, and then sync, as shown in the next listing.

public static boolean syncStream(FileOutputStream fos) {
try {
if (fos != null) {
try {
fos.getFD().sync();
} catch (IOException e) {
Log.e(Constants.LOG_TAG,
"Error syncing fos " + e.getMessage(), e);
}
return true;
}
return false;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐