chf是前文的一个FileChannel
ByteBuffer buf = ByteBuffer.allocate(50);
chf.read(buf);
buf.flip();
byte [] byt = new byte[100];
buf.get(byt);
然后就出来了 :
Exception in thread "main" java.nio.BufferUnderflowException
at java.nio.HeapByteBuffer.get(Unknown Source)
at java.nio.ByteBuffer.get(Unknown Source)
at Sample.main(Sample.java:22)
请问这怎么办
|