public class GetData {
private static final int BSIZE = 1024;
public static void main(String[] args) {
ByteBuffer bb = ByteBuffer.allocate(BSIZE);
int i = 0;
while(i++ < bb.limit()){
System.out.println(i);
if(bb.get() != 0){
System.out.println("nonzero");
}else{
if(i == 512){
System.out.println(bb.get());
}
}
}
}
}
结果Exception in thread "main" java.nio.BufferUnderflowException
at java.nio.Buffer.nextGetIndex(Buffer.java:492)
at java.nio.HeapByteBuffer.get(HeapByteBuffer.java:135)
at java_nio.GetData.main(GetData.java:13)