buffertester.java

来自「这是孙卫琴在"Java与面向对象编程"一书的源代码。」· Java 代码 · 共 30 行

JAVA
30
字号
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
public class BufferTester {
  public static void main(String args[])throws IOException{
     final int BSIZE=1024;
     //把test.txt文件中的数据拷贝到out.txt中
     FileChannel in=new FileInputStream("D:\\test.txt").getChannel();
     FileChannel out=new FileOutputStream("D:\\out.txt").getChannel();

     ByteBuffer buff=ByteBuffer.allocate(BSIZE);
     while(in.read(buff)!=-1){
       buff.flip();
       out.write(buff);
       buff.clear();
     }
     in.close();
     out.close();
  }
}




/****************************************************
 * 作者:孙卫琴                                     *
 * 来源:<<Java面向对象编程>>                       *
 * 技术支持网址:www.javathinker.org                *
 ***************************************************/

⌨️ 快捷键说明

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