关于rewind()
jadic 2007-10-14 08:52:20 import java.io.*;
import java.nio.*;
public class BatchWriter {
public static void main(String[] args)throws IOException {
ByteBuffer bb=ByteBuffer.allocate(1024);
IntBuffer ib=bb.asIntBuffer();
ib.put(new int[]{10,20,30,40,50});
System.out.println(ib.get(3));
ib.put(3, 100);
System.out.println(ib.get(3));
ib.rewind();
while(ib.hasRemaining()){
int i=ib.get();
if(i==0) break;
System.out.println(i);
}
}
}
上面结果打印
40
100
10
20
30
100
50
但我把ib.rewind()去掉,为什么就只打印
40
100
当前位置不是3吗,50为什么不打印了? 谢谢