I want to change a file's content,such as ,I want to delete or modify a random line of a file.
How to do this?
Printable View
I want to change a file's content,such as ,I want to delete or modify a random line of a file.
How to do this?
You can open a second file read from the first and write to the second. In the process you can make your modifications. For example skipping a line etc. When done close second file(with a temporary name), delete the origianl and rename the temp file to the original name. A bit safer than reading the file into memory truncating the file to zero length and writing from memory to file.
Hope this helps