[英]Detect when I can force unmount usb-otg flash drive after writing file
I write file to flash drive: 我将文件写入闪存驱动器:
out.write(bytes);
out.flush();
out.close();
Then I need faster remove usb-org flash drive. 然后,我需要更快地卸下USB-org闪存驱动器。 And now file not fully written down to flash drive.
现在文件还没有完全写入闪存驱动器。 How to detect when file fully written down?
如何检测何时将文件完全记录下来?
Rather than the code you have, assuming out
is a FileOutputStream
, do this: 而不是你,假设码
out
是一个FileOutputStream
,这样做:
out.write(bytes);
out.flush();
out.getFD().sync();
out.close();
After sync()
, the bytes will have been written completely to disk. 在
sync()
,字节将被完全写入磁盘。 This puts added emphasis on doing all of this I/O on a background thread, off of the main application thread. 这更加强调了在主应用程序线程之外的后台线程上执行所有这些I / O。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.