我不是李大侠 2018-02-06 02:30 采纳率: 0%
浏览 1798
已结题

关于ByteBuffer的position和limit的问题

@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有什么影响?
求解答

  • 写回答

7条回答 默认 最新

  • lyter1214 2018-02-06 02:33
    关注

    我自己用你的代码,按你的方法测试,并没有这用的情况呀

    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记