skycqd
skycqd
2017-08-07 05:50

java ByteBuffer clear()问题,下面这段代码为什么会死循环

  • java
  • buffer

public static void main(String[] args) throws IOException,
ClassNotFoundException, InstantiationException, IllegalAccessException {
File f=new File("D:/1.txt");
FileChannel chanel=new RandomAccessFile(f,"rw").getChannel();
MappedByteBuffer map=chanel.map(FileChannel.MapMode.READ_ONLY,0,f.length() );
java.nio.ByteBuffer buffer=java.nio.ByteBuffer.allocate(256);
Charset charset=Charset.forName("utf-8");
CharsetDecoder decorder=charset.newDecoder();

    while((chanel.read(buffer))!=-1){

        buffer.flip();
        CharBuffer cb=charset.decode(buffer);
        System.out.println(cb);
        //buffer.clear();

    }

}
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐

换一换