Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete a line in file (Android/java)

Tags:

java

android

In my app (Android) I create a file. To this file I add a line by line after some situation. Then I send a data to the server line by line. When all transmission is OK I erase the file, like this:

fos_kasowanie_pliku = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos_kasowanie_pliku.write("".getBytes());
fos_kasowanie_pliku.close();

Can I delete only 1 line (first one) after sending this to the server? I read that I should rewrite the file without this line. Is there a better solution?

like image 300
Piotr Cyliński Avatar asked Jun 23 '26 08:06

Piotr Cyliński


1 Answers

You may consider using a database, where you can add records, then send the data to the server, and then delete records in any order you prefer. Databases, unlike plain old files, are designed to handle exactly the problem you are describing.

like image 71
lenik Avatar answered Jun 24 '26 22:06

lenik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!