简体   繁体   English

Java RandomAccessFile通过写入偏移量扩展文件

[英]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. 所以我知道您可以通过写一个超过当前大小的文件来扩展RandomAccessFile的大小,但是我似乎找不到特定情况下的任何信息。

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? 如果我有一个10字节的文件,并且我写了5个字节,偏移量为15,则文件扩展为20个字节,但是,对于文件的旧端与我开始写的位置之间的字节,可以保证吗? For example are they guaranteed to be all zeros or is it undefined? 例如,它们是否保证全为零或未定义?

From the Java doc : Java文档

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. 如果使用length方法返回的文件的当前长度小于newLength参数,则将扩展文件。 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. 所以不,没有值可以保证,当然也不是全零。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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