这是通过
java.nio*** 作执行此 *** 作的方法:
public static void copyFile(File sourceFile, File destFile) throws IOException { if(!destFile.exists()) { destFile.createNewFile(); } FileChannel source = null; FileChannel destination = null; try { source = new FileInputStream(sourceFile).getChannel(); destination = new FileOutputStream(destFile).getChannel(); // previous pre: destination.transferFrom(source, 0, source.size()); // to avoid infinite loops, should be: long count = 0; long size = source.size();while((count += destination.transferFrom(source, count, size-count))<size); } finally { if(source != null) { source.close(); } if(destination != null) { destination.close(); } }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)