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?

Can you re-phrase your question, please?

Sure!

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.

Member Avatar for hfx642

Append???
This would move the EoF to the end (again).

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

Member Avatar for hfx642

Well... If it's your own EoF "marker", then you should be able to read it.

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]

I like it. That's not what I wanted to do, but it'll work!

Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.