FileChannel fc = new FileInputStream("data.txt").getChannel();ByteBuffer buff = ByteBuffer.allocate(1024);fc.read(buff);buff.flip();?while (buff.hasRemaining())?这里判断当前位置与限制为之间是否有元素,System.out.print((char) buff.ge

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/27 19:10:08
FileChannelfc=newFileInputStream("data.txt").getChannel();ByteBufferbuff=ByteBuffer.allocate(1024);f

FileChannel fc = new FileInputStream("data.txt").getChannel();ByteBuffer buff = ByteBuffer.allocate(1024);fc.read(buff);buff.flip();?while (buff.hasRemaining())?这里判断当前位置与限制为之间是否有元素,System.out.print((char) buff.ge
FileChannel fc = new FileInputStream("data.txt").getChannel();
ByteBuffer buff = ByteBuffer.allocate(1024);
fc.read(buff);
buff.flip();?
while (buff.hasRemaining())?这里判断当前位置与限制为之间是否有元素,
System.out.print((char) buff.get());

FileChannel fc = new FileInputStream("data.txt").getChannel();ByteBuffer buff = ByteBuffer.allocate(1024);fc.read(buff);buff.flip();?while (buff.hasRemaining())?这里判断当前位置与限制为之间是否有元素,System.out.print((char) buff.ge
如果结合API文档,就清晰多了.
1、
public final Buffer flip()
Flips this buffer.The limit is set to the current position and then
the position is set to zero.If the mark is defined then it is
discarded.
2、看英文的意思,判断是否还有数据,有则继续循环