Java: 复制文件最快方法
2013-12-10 21:04
671 查看
不考虑多线程优化,单线程文件复制最快的方法是(文件越大该方法越有优势,一般比常用方法快30+%):
private static void nioTransferCopy(File source, File target) {
FileChannel in = null;
FileChannel out = null;
FileInputStream inStream = null;
FileOutputStream outStream = null;
try {
inStream = new FileInputStream(source);
outStream = new FileOutputStream(target);
in = inStream.getChannel();
out = outStream.getChannel();
in.transferTo(0, in.size(), out);
} catch (IOException e) {
e.printStackTrace();
} finally {
close(inStream);
close(in);
close(outStream);
close(out);
}
}
private static void nioTransferCopy(File source, File target) {
FileChannel in = null;
FileChannel out = null;
FileInputStream inStream = null;
FileOutputStream outStream = null;
try {
inStream = new FileInputStream(source);
outStream = new FileOutputStream(target);
in = inStream.getChannel();
out = outStream.getChannel();
in.transferTo(0, in.size(), out);
} catch (IOException e) {
e.printStackTrace();
} finally {
close(inStream);
close(in);
close(outStream);
close(out);
}
}
相关文章推荐
- Java中的4种文件复制方法
- 4 Ways to Copy File in Java -- Java 复制文件的方法
- java 3中方法复制一个文件
- java中File类中的常用的方法 复制,读文件
- 复制文件或文件夹Java方法
- java复制文件的简单方法
- Java: 复制文件最快方法
- JAVA中IO流部分复制文件常用的四中方法
- Java 高效复制文件方法
- java大文件复制最高效方法:多线程FileChannel
- 【Java学习笔记】基础知识学习19【一个大文件的复制方法】
- java高效的文件复制方法
- Java IO学习【13】利用字节流复制文件的4种方法详解
- java文件复制最快的方法!
- Java: 复制文件最快方法
- Java: 复制文件最快方法
- Java: 复制文件最快、高效率的方法
- Java中的4种文件复制方法
- Java: 复制文件最快方法
- 将某盘的java文件复制到目标文件的方法。