ByteBuffer byteBuffer = ByteBuffer.allocate(1024);

   //Direct Buffer的效率会更高。
//   ByteBuffer byteBuffer = ByteBuffer.allocateDirect(1024);     

   long start = System.currentTimeMillis();
while(true)
{
int eof = inChannel.read(byteBuffer);
if(eof == -1 ) break;
byteBuffer.flip();
    outChannel.write(byteBuffer);
byteBuffer.clear();
}
System.out.println("spending : " + (System.currentTimeMillis()-start));
inChannel.close();
outChannel.close();

}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
  • 2021-09-15
  • 2021-06-12
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-28
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2021-08-24
  • 2022-01-29
  • 2022-12-23
相关资源
相似解决方案