首页 > 学院 > 开发设计 > 正文

最快复制文件方法() out.transferFrom(in, 0, in.size());

2019-11-14 21:39:04
字体:
来源:转载
供稿:网友
最快复制文件方法() out.transferFrom(in, 0, in.size());
 1 package test; 2 import java.io.*; 3 import java.nio.channels.FileChannel; 4 public class Test31 5 { 6     public static void main(String[] args) throws Exception 7     { 8         String dir = "E:/"; 9         // 调用方法10         copyFile(dir + "DV-1676.mp4", dir + "DV-1676_copy.mp4");11     }12     public static boolean copyFile(String readfile, String writefile) throws Exception13     {14         FileInputStream fis = null;15         FileOutputStream fos = null;16         // 定义两个直连的文件管道17         FileChannel in = null, out = null;18         fis = new FileInputStream(readfile);19         fos = new FileOutputStream(writefile);20         in = fis.getChannel();21         out = fos.getChannel();22         // 直接让流流向要拷贝的文件23         out.transferFrom(in, 0, in.size());24         in.close();25         out.close();26         fis.close();27         fos.close();28         return true;29     }30 }


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表