认识nio中buf的三个常用属性

public static void main(String[] args) {

		IntBuffer buf = IntBuffer.allocate(10);
		System.out.println("1、在写入数据之前的position、limit、capacity的值:");
		System.out.println("position = "+buf.position()+" , limit = "+buf.limit()+" , capacity = "+buf.capacity());
		int temp[] = {5,7,9};
		buf.put(3);
        buf.put(temp);
        System.out.println("2、写入数据之后的postion、limit、capacity的值");
        System.out.println("position = "+buf.position()+"  , limit = "+buf.limit()+" , capcity = "+ buf.capacity());
        buf.flip();
        System.out.println("3、写入数据之后的postion、limit、capacity的值");
        System.out.println("position = "+buf.position()+"  , limit = "+buf.limit()+" , capcity = "+ buf.capacity());

        while(buf.hasRemaining()){
        	int x = buf.get();
        	System.out.print(x+ " 、  ");
        }

		
	
	}

你可能感兴趣的:(认识nio中buf的三个常用属性)