简体   繁体   中英

Java RandomAccessFile extending file by writing with an offset

So I know you can extend the size of a RandomAccessFile by writing past its current size but I can't seem to find any info for a specific case.

If I have a 10 byte file and I write 5 bytes with an offset of 15 the file gets extended to 20 bytes, but is there any guarantee as to what the bytes are between the old end of the file and where I started writing? For example are they guaranteed to be all zeros or is it undefined?

From the Java doc :

If the present length of the file as returned by the length method is smaller than the newLength argument then the file will be extended. In this case, the contents of the extended portion of the file are not defined.

So no, no values are guaranteed, certainly not all zeros.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM