0

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?

ziniestro
  • 686
  • 1
  • 11
  • 24
way
  • 1
  • Possible duplicate of [How can I lock a file using java (if possible)](https://stackoverflow.com/questions/128038/how-can-i-lock-a-file-using-java-if-possible) – Pronoy999 Sep 15 '17 at 05:01

1 Answers1

0

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.

Pronoy999
  • 645
  • 6
  • 25