I’m writing bytes to a random access file. After completing the operation, I want to delete the first 100 bytes from the file. How can I achieve this?
Thanks in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
AFAIK, you will need to copy the remaining bytes (file length – 100) to a new file. Deleting the first 100 bytes from a file is not possible without copying the remaining bytes to a new file.
Edit: As cdhowie rightly pointed out, you could:
Then repeat the process until the entire file is written. Finish off by setting the filelength 100 bytes less than previously. If you want to be on the safe side and not risk corrupting the original file, it could be worth writing to a temp file first.