gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 07:46:58 25 4
gpt4 key购买 nike

所以我知道您可以通过写入超过其当前大小来扩展 RandomAccessFile 的大小,但我似乎无法找到特定情况的任何信息。

如果我有一个 10 字节的文件,我写了 5 个字节,偏移量为 15,文件会扩展到 20 个字节,但是对于文件的旧结尾和我开始的地方之间的字节有什么保证吗写作?例如,它们保证全为零还是未定义?

最佳答案

来自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.

所以不,没有任何值是有保证的,当然不是全为零。

关于Java RandomAccessFile 通过写入偏移量来扩展文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24942603/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com