Delete line in file (Android / java)

In my application (Android) I am creating a file. To this file, I add line by line after some situation. Then I send the data to the server in turn. When the whole transfer is OK, I delete the file as follows:

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

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

+3
source share
3 answers

You can use a database where you can add records, then send data to the server, and then delete the records in any order. Databases, unlike simple old files, are designed to handle exactly the problem that you are describing.

+5
source

- . .

+2

I think a rewirite file removing a line is the only solution. or you can try to use a database like SqLite . You can easily delete entries.

0
source

All Articles