@Test
public void test() throws Exception{
FileInputStream fis = new FileInputStream("D:\1.jpg");
FileOutputStream fos = new FileOutputStream("D:\2.jpg");
//获取通道
FileChannel inChannel = fis.getChannel();
FileChannel outChannel = fos.getChannel();
//分配指定大小缓存区
ByteBuffer buff = ByteBuffer.allocate(1024);
System.out.println("-----ByteBuffer.allocate(1024)-----");
System.out.println("position"+buff.position());
System.out.println("limit"+buff.limit());
}
这个test在run下输出为
-----ByteBuffer.allocate(1024)-----
position0
limit1024
将断点打在System.out.println("position"+buff.position());这个代码前面,debug下输出为
-----ByteBuffer.allocate(1024)-----
position1024
limit1024
如果将
FileInputStream fis = new FileInputStream("D:\1.jpg");
FileOutputStream fos = new FileOutputStream("D:\2.jpg");
//获取通道
FileChannel inChannel = fis.getChannel();
FileChannel outChannel = fos.getChannel();
注释掉,run和debug输出是一样的
-----ByteBuffer.allocate(1024)-----
position1024
limit1024
获取通道FileChannel对ByteBuffer有什么影响?
求解答
关于ByteBuffer的position和limit的问题
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-