Android Question How Safe to Delete/write/read text file?

john1in2

Member
Licensed User
With all the processes going on all the time in our phones, I was wondering about this.

My App will take data and when it is valid write it to a data file like this-
- deletes data file
- writes data file
- reads data file

We are talking about a text file of about 2000 lines, so not that big.

If there is an error during delete or write, the data file will be corrupted, which will cause the app to crash massively.

So I am wondering how concerned I should be? The major problem being if something interrupts the write cycle and stops the writing, in which case the app will be unusable.

-thanks.
 

KMatle

Expert
Licensed User
Longtime User
It depends how you do it. The file system is very stable so I assume you're talikg about when you want to write 2000 lines and your app goes to sleep or so due to user action. I would put the code to read/write/delete in a service as it will finish it's work. Today I put all non ui relevant code in services. If you can, use a sqlite db as it comes with additional features to keep data integrity.
 
Upvote 0
Top