Soham
Soham

Reputation: 4960

Reading a file while it is being written

Overview

Problem:

Things tried

Upvotes: 4

Views: 1213

Answers (1)

Kevin van Mierlo
Kevin van Mierlo

Reputation: 9814

You need to lock when you write or read your file. This way only one thread can access the file.

Here is the official android website explaining a lock:

http://developer.android.com/reference/java/util/concurrent/locks/Lock.html

Here is an example using a lock:

https://stackoverflow.com/a/3392615/2767703

You can also use synchronized to lock an object, here is it explained:

Java Synchronization

Upvotes: 1

Related Questions