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 }
新闻热点
疑难解答