12.直接拷贝(零拷贝)和间接拷贝

2019-03-04  本文已影响0人  未知的证明

学完操作系统回来再写

public class NioTest8 {
    public static void main(String[] args) throws IOException {


        FileInputStream fileInputStream = new FileInputStream("input2.txt");
        FileOutputStream fileOutputStream = new FileOutputStream("output2.txt");
        FileChannel fileInputStreamChannel = fileInputStream.getChannel();
        FileChannel fileOutputStreamChannel = fileOutputStream.getChannel();

        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(512);

        while (true){

            byteBuffer.clear();
            int read = fileInputStreamChannel.read(byteBuffer);
            if (-1 == read) break;

            byteBuffer.flip();

            fileOutputStreamChannel.write(byteBuffer);


        }
        fileInputStreamChannel.close();
        fileOutputStreamChannel.close();


    }
}
上一篇下一篇

猜你喜欢

热点阅读