美文网首页
12.直接拷贝(零拷贝)和间接拷贝

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

作者: 未知的证明 | 来源:发表于2019-03-04 20:45 被阅读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();
    
    
        }
    }
    

    相关文章

      网友评论

          本文标题:12.直接拷贝(零拷贝)和间接拷贝

          本文链接:https://www.haomeiwen.com/subject/btimuqtx.html