java copyfile 复制文件

//事先定义好输入输出路径即可
//输入文件路径 inputPath
//输出文件路径 outPaht
File  copyFile  =  new File(inputPath);
File  destFile  =  new  File(outPaht);
copyFileChannels(copyFile , destFile );

private static  void copyFileChannels(File source , File destFile)  throws  IOException{
	FileChannel inputChannel  = null;
	FileChannel outputChannel  = null;
	try{
		inputChannel  =  new  FileInputStream(source).getChannell;
		outputChannel  =  new  FileInputStream(destFile).getChannell;
		outputChannel.transferFrom(inputChannel , 0 , inputChannel.size());
	}
	finally{
		inputChannel.close;
		outputChannel.close;
	}
}

你可能感兴趣的:(java)