简体   繁体   English

Android内部存储同时读取/写入

[英]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. 我正在使用Android提供的内部存储来读写同一文件中的数据。 See https://developer.android.com/guide/topics/data/data-storage.html#filesInternal 请参阅https://developer.android.com/guide/topics/data/data-storage.html#files内部

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? 我的问题是我是否需要围绕读写方法实现同步逻辑,以防止竞速或Android内部存储在后台提供这种保护?

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. 当您从输出流中收到I / O错误时,您应该能够在其中包裹try / catch块,然后将您的应用设置为稍后重试,或者针对特定应用执行任何所需的行为。

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. 如果您可以描述为什么要同时从多个进程写入文件,那么可能会建议其他解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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