java io 通过文件通道对文件进行复制操作

public static void main(String[] args) throws IOException {
      
        
        File file=new File("C:\\Users\\Desktop\\AAA.txt");
        
        FileInputStream fis=new FileInputStream(file);//原文件
        
        FileOutputStream fos=new FileOutputStream(".//des.txt");//目标文件
        
        
        FileChannel fc=fis.getChannel();//获得原文件的通道
        
        FileChannel des=fos.getChannel();//目标文件的通道
        
        
        
        fc.transferTo(0,fc.size() , des); //连接通道,从fc通道读取,写入到des通道。
        
        
        //关闭流操作
        fc.close();
        des.close();
        fis.close();

        fos.close();





猜你喜欢

转载自blog.csdn.net/Bigbig_Hydra/article/details/80280622