java - 如果在执行 FileChannel.map() 时 MappedByteBuffer 的大小大于文件长度,会发生什么

标签 java memory-mapped-files

我正在尝试将随机访问文件映射到内存,然后想要附加一些数据。 MappedByteBuffer buffer = file.getChannel().map(MapMode.READ_WRITE, 0, size);

如果 size > file.length 会发生什么?

最佳答案

这个问题的答案在 Javadoc 中:

The behavior of this method when the requested region is not completely contained within this channel's file is unspecified.

关于java - 如果在执行 FileChannel.map() 时 MappedByteBuffer 的大小大于文件长度,会发生什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11271546/

相关文章:

java - 使用 Springs @Autowired 进行独立的 JUnit 测试

java - 在 hibernate : is it possible to mix Annotations and XML configuration for an Entity?

java - 为什么我会收到错误 "package org.mockito.runners does not exist"?

c - 内存映射文件

java - 我应该为我的简单流程使用内存映射文件吗?

java - 在远程 teamcity 构建代理上运行 selenium 自动化测试

java - 在构造函数之外的方法中使用构造函数中的变量

linux - 操作系统如何知道映射内存中的页面是脏的?

c - 如何正确地字节移位一大块数据?

C 内存映射文件与常规文件