• Post Reply Bookmark Topic Watch Topic
  • New Topic

Stream for reading and deleting line

 
Manas Ahlaad
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have to read a line from a text file and then delete that line from the file.which stream will be fit for it ?
TIA
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's really no single stream that can do this. What you'll probably have to do is read from one file and write to another. For each line that you read from the first file, after reading it you decide whether or not it should be copied to the new file, and then either write it there, or don't. After you're done reading everything, close both streams, delete the original file, and rename your new file to the name of the old file.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!