简体   繁体   中英

Android Internal storage read/write at the same time

I am using Android provided internal storage to write and read the data in the same file. See https://developer.android.com/guide/topics/data/data-storage.html#filesInternal

My question is do I need to implement a synchronized logic around my read and write methods to prevent the racing or Android internal storage provides such protection under the hood?

If it's two separate applications/processes altogether, the underlying filesystem should lock the files. When you get an I/O error from your output stream, you should be able to wrap a try/catch block around that, and then set your app up to retry later, or whatever the desired behavior is for your particular application.

Files aren't really designed to be written to simultaneously by multiple applications.

If you can maybe describe why you want to write to a file simultaneously from multiple processes, there may be other solutions that could be suggested.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM