File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading and deleting the same line in a File

 
Zico Gupta
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47228
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic