也就是说,如果我这样做:
channel.position(0)
channel.read(buffer); // will read in 1st byte of file and so on
对比
channel.position(1)
channel.read(buffer); // will read in 2nd byte of file and so on
我的假设正确吗?阅读文档并没有真正说明这一点,所以我想确保
也就是说,如果我这样做:
channel.position(0)
channel.read(buffer); // will read in 1st byte of file and so on
对比
channel.position(1)
channel.read(buffer); // will read in 2nd byte of file and so on
我的假设正确吗?阅读文档并没有真正说明这一点,所以我想确保
FileChannel position(long newPosition) 是否为 0 索引?
是的。
阅读文档并没有真正说明这一点,所以我想确保
我很清楚。javadocposition()
说:_
“返回:此通道的文件位置,一个非负整数,计算从文件开头到当前位置的字节数”。
“[A] 非负整数”表示零或更大。如果他们的意思是一个或更大,他们会写成“一个正整数”或“一个严格的正整数”。
该方法是 0 索引的。
此外,当您调用 read 方法时,文件位置会更新为实际读取的字节数。通道的 position() 方法返回当前位置。