filechannelexample5.java
来自「JAVA SE6 全方位学习 朱仲杰 编著 机械工业出版社出版」· Java 代码 · 共 25 行
JAVA
25 行
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
public class FileChannelExample5
{
public static void main(String args[]) throws Exception
{
FileInputStream fin = new FileInputStream("data1.txt");
ByteBuffer b[] = new ByteBuffer[2];
b[0] = ByteBuffer.allocate(10);
b[1] = ByteBuffer.allocate(10);
FileChannel fc = fin.getChannel();
fc.read(b);
fc.close();
b[0].flip();
b[1].flip();
while(b[0].hasRemaining())
System.out.println("b[0]: "+b[0].getChar());
while(b[1].hasRemaining())
System.out.println("b[1]: "+b[1].getChar());
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?