Possible Duplicate:
Replace first line of a text file in Java
Java – Find a line in a file and remove
I am trying to find a way to remove the first line of text in a text file using java. Would like to use a scanner to do it…is there a good way to do it without the need of a tmp file?
Thanks.
This will return the first line of text from the file and discard it because you don’t store it anywhere.
To overwrite your existing file:
Note that you will have to be catching and handling some
IOExceptions this way. Also, theif()... else()...statement is necessary in thewhile()loop to keep any line breaks present in your text file.