怎么换算的啊?进制数之间可以转换,为什么两个不同计量单位之间也可以转换啊?
代码如下:
import java.nio.*;
import java.nio.channels.*;
import java.io.*;
import static net.mindview.util.Print.*;
public class LargeMappedFiles {
static int length = 0x8FFFFFF; // 128 MB
public static void main(String[] args) throws Exception {
MappedByteBuffer out =
new RandomAccessFile("test.dat", "rw").getChannel()
.map(FileChannel.MapMode.READ_WRITE, 0, length);
for(int i = 0; i < length; i++)
out.put((byte)'x');
print("Finished writing");
for(int i = length/2; i < length/2 + 6; i++)
printnb((char)out.get(i));
}
}
PHP中文网2017-04-17 17:37:27
應該是一個筆誤吧,你用計算機可以算下 128MB是0x8000000,或者你自己測下,產生的test.data就是143MB的
RandomAccessFile randomAccessFile = new RandomAccessFile("test.data", "rw");
FileChannel channel = randomAccessFile.getChannel();
ByteBuffer buffer = channel.map(FileChannel.MapMode.READ_WRITE, 0, 0x8FFFFFF);
PHP中文网2017-04-17 17:37:27
應該是程式碼跟註解不同步吧。例如本來是0x8000000,也就是128MB,後來因為某些原因改成0x8FFFFFFF了,但忘了改註解。或者乾脆就是筆誤。感覺這是一個典型的「無用」註解。