The write() function in java appends new data to end of file. Here is my question; how the java knows end of file?
- By reading whole file to find end of file
- It knows where the end of file
Which one? 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.
For Unix / Linux at least, the answer is that the operating system takes care of this. Java just makes use of the operating system provided file descriptor that keeps track of the application’s current position within the file.
If you opened the file normally (append == false), then a
writewrites data at the file descriptor’s current position, and then updates it to point to the position immediately after the data just written.If you opened the file in append mode (append == true), then each
writewrites data at the current end of file.Note that other Unix / Linux I/O operations use and update the current position of a file descriptor; e.g.
read,seekandtell.