I need to take the end off of a file. What I mean is that I have a file, and it has an end marker, but I can't write past the end marker. Is there a way to do this?

6 Years
Discussion Span
Last Post by jackmaverick1


I need to find a way to take the end off of a file. The file has an end marker that will prevent my program from reading past it. In short, I need to take the end off a file, and replace it with a new string.


Yes, but I have my own sort of EOF marker, and I need to input my new string just before that marker.


OK, here's the design.

[Exception Trap begin]
Open a BufferedReader to the original file.
Open a BufferedWriter to a temporary file.
Loop through each line of the file testing for the custom end of file marker.
If not found, write the line to the temp file.
If found, write the NEW CONTENT to the temp file and write custom EOF in temp file.
Close the temp file.
Close the original file.
Delete original file.
Rename temp file to original file name.
[Exception Trap end]

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.