The following simple java method implements a simple way to remove a set of consecutive lines from a text file.

It can be used to:

  • remove first n lines from a text file
  • remove last n lines from a text file
  • remove lines from n to m in a text file

To do the work, the deleteLines method uses the getNumberOfLines method I explained in how to count the number of lines

Here you are the source of the method:

 

To use the method just use the following calls:

Gg1