3 ms·
There's nothing inherently wrong with reading and writing to the same file (as least if it is a binary file). And if you read at offset x and write at offset x-
by seppel 6y ago
There's nothing inherently wrong with reading and writing to the same file (as least if it is a binary file). And if you read at offset x and write at offset x-y you can easily move contents around with only a very small buffer. Just be sure that you move in the correct direction, so that you dont override stuff you need later.
That people normally use temporary files, has two reasons: The first is that it is much safer if something goes wrong. You then still have the original and not some half-way processed file. The other reason is that reading and writing in text mode does not really work. But you can of course process text files as binary files and deal with line endings yourself.