Read/Delete top line from a File

  • Thread starter Thread starter J Wolfgang Goerlich
  • Start date Start date
J

J Wolfgang Goerlich

Hello group,

I am looking for an easy way to read the top line from a text file and
delete it. The text file is a working queue. If no lines exist, the
thread simply waits.

I am running into difficulty because it seems that I need a
StreamWriter and StreamReader with a lock on the same file.

Does anyone have some precanned code samples for popping the top line
off a file?

Thanks in advance,

J Wolfgang Goerlich
 
Hello group,

I am looking for an easy way to read the top line from a text file and
delete it. The text file is a working queue. If no lines exist, the
thread simply waits.

I am running into difficulty because it seems that I need a
StreamWriter and StreamReader with a lock on the same file.

Does anyone have some precanned code samples for popping the top line
off a file?

Thanks in advance,

J Wolfgang Goerlich

It cannot be simpler than this:
-open file to read
-create tmp file using Path.GetTempfileName
remove the first line of the file
dump the rest of the file to the temp file
close both files
copy from tmp to real file
 
Back
Top