wood burning stoves 2.0*
The moose likes Java in General and the fly likes Reading and deleting the same line in a File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Reading and deleting the same line in a File" Watch "Reading and deleting the same line in a File" New topic
Author

Reading and deleting the same line in a File

Zico Gupta
Greenhorn

Joined: Apr 27, 2011
Posts: 10
Hello,
I'm trying to read some lines from a file from the begging and delete those lines after reading them so that next time I don't have to read those which already being read.
The problem is, till now I able to remove the last lines(s) using following code :



This code reads the first line i.e. omes1.xml, but deletes 'omes3.xml' from the end. Is there any solution which will remove only 'omes1.xml' after reading?

Thanks & Regards,
Zico
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12791
    
    5
As you have found, you can cut from the end of a file but:

You can't just reach into the middle of a file and delete data, you have to write a modified file, delete the old and rename.

Bill
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39070
    
  23
And welcome to the Ranch
 
GeeCON Prague 2014
 
subject: Reading and deleting the same line in a File