There is a task to "scroll" the data of the form-lines through the file. The file must be no more than 1000 lines. When the file is full, the old lines are erased (top).

In addition to the option to download data, delete the file, save the data, what else is there? Better code.

  • 2
    - open the file. count the number of rows (N) - the number of rows to delete (D) = N + C - 1000, (C) - the number of rows to add. - open the file. delete the first "C" lines - open the file for append. if it is not known in advance how many lines will be added to the file, then you can first append to the file and then delete it - jmu
  • - open the file. we delete the first "C" lines and do not tell me which command or which method did you mean? - hitman249
  • one
    As such, there is no removal. because we work with streams (continuous data sets). you need to open a stream to read and write to a single file. Ie in a cycle do read and write (buffered). you need to delete the first 5 lines, - skip them in a loop. example: - jmu

1 answer 1

Here is an example of a small, but here you can read about java io , + many examples.