码迷,mamicode.com
首页 > 其他好文 > 详细

演示缓冲区的操作流程

时间:2014-09-09 10:59:38      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:style   color   os   io   java   ar   for   on   c   

import java.nio.IntBuffer;

public class IntBufferDemo01 {
    public static void main(String[] args) {
        IntBuffer buf = IntBuffer.allocate(10);
        System.out.print("The position,limit and capacity before input data:");
        System.out.println("position=" + buf.position() + ",limit="
                + buf.limit() + ",capacity=" + buf.capacity());
        int temp[] = { 3, 4, 5 };
        buf.put(3);
        buf.put(temp);
        System.out.print("The position,limit and capacity after input data:");
        System.out.println("position=" + buf.position() + ",limit="
                + buf.limit() + ",capacity=" + buf.capacity());
        buf.flip();
        System.out.print("The position,limit and capacity when outputing:");
        System.out.println("positon=" + buf.position() + ",limt=" + buf.limit()
                + ",capacity=" + buf.capacity());
        System.out.print("The content in buffer:");
        while (buf.hasRemaining()) {
            int x = buf.get();
            System.out.print(x + ",");
        }
    }
}

The output:

The position,limit and capacity before input data:position=0,limit=10,capacity=10
The position,limit and capacity after input data:position=4,limit=10,capacity=10
The position,limit and capacity when outputing:positon=0,limt=4,capacity=10
The content in buffer:3,3,4,5,

演示缓冲区的操作流程

标签:style   color   os   io   java   ar   for   on   c   

原文地址:http://www.cnblogs.com/vonk/p/3961440.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!