Delete first line from file
Hi,
I want to do next (pseudo code)
int counter = 0;
void openFile(){
open file f;
}
void closeFile(){
close file f;
}
void writeToFile(String s){
if (counter > MaxLines){
delete first line from file f
counter--;
}
append to file f string s;
counter++;
}
How I can code this? It is not matter what I will use to open, write, read and close file. I just want to delete first line from file, but not to close it and be able to write.
Thank you.
[939 byte] By [
boba5555a] at [2007-11-26 15:24:44]

# 1
You cannot delete or insert bytes or lines or anything else you want to call it in the beginning or middle of a file. It is impossible.
You can do any of the following
- add lines at the end
- truncate the file to a new length (removing data from the end of the file)
- replace content anywhere in the file (this is only possible with fixed length records)
- create a new file and copy the contents from old to new skipping the ones you want to "delete"