This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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: 13001
    
    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: 43995
    
  33
And welcome to the Ranch
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Reading and deleting the same line in a File
 
It's not a secret anymore!