⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newioexample4.java

📁 JAVA SE6 全方位学习 朱仲杰 编著 机械工业出版社出版
💻 JAVA
字号:
import java.nio.*;

public class NewIOExample4
{
	public static void main(String args[])
	{
		char c[] = {'a', 'b', 'c', 'd', 'e'};
		CharBuffer b1 = CharBuffer.allocate(10);
		
		b1.put(c);	
		b1.flip();
		b1.position(2);
		CharBuffer b2 = b1.slice();
		print(b1);
		print(b2);
		
		while (b2.hasRemaining())
			System.out.print(b2.get()+" ");
		System.out.println();
		
		b1.put(4, 'x');
		b2.rewind();
		while (b2.hasRemaining())
			System.out.print(b2.get()+" ");
		System.out.println();
	}
	
	public static void print(Buffer b)
	{
		System.out.println("Position: "+b.position());
		System.out.println("   Limit: "+b.limit());
		System.out.println("Capacity: "+b.capacity());
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -