首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >buffer.flip()方法的确切功能是什么?

buffer.flip()方法的确切功能是什么?
EN

Stack Overflow用户
提问于 2018-09-28 00:15:09
回答 1查看 383关注 0票数 0

try (FileOutputStream binFile =新FileOutputStream("data.dat");FileChannel binChannel = binFile.getChannel()) {

代码语言:javascript
复制
        ByteBuffer buffer = ByteBuffer.allocate(100);
        byte[] outputBytes = "Hello World!".getBytes();
        buffer.put(outputBytes);
        long int1Pos = outputBytes.length;
        buffer.putInt(245);

        binChannel.write(buffer);

        java.io.RandomAccessFile ra = new java.io.RandomAccessFile("data.dat", "rwd");
        FileChannel channel = ra.getChannel();

        ByteBuffer readBuffer = ByteBuffer.allocate(100);

        channel.position(int1Pos);
        channel.read(readBuffer);
        readBuffer.flip();
        System.out.println("Int3 = " + readBuffer.getInt());
         } catch(IOException e){
         }
EN

回答 1

Stack Overflow用户

发布于 2018-09-28 00:25:50

您应该签出其中的Java文档。https://docs.oracle.com/javase/7/docs/api/java/nio/Buffer.html

翻转此缓冲区。在一系列通道读取或put操作之后,调用此方法为通道写入或相对get操作序列做准备。例如:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52541202

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档