import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class Test {
?public static void main(String[] args) throws Exception {
??if (args.length != 2){ //表示一定需要两个参数
???System.out.println("Wrong File operation !!!");
???System.exit(1);
??}
??File inFile = new File(args[0]) ;
??File outFile = new File(args[1]) ;
??if (!inFile.exists()){ //判斷文件是否存在,不存在則退出
???System.out.println("File not existed!!!");
???System.exit(1);
??}
??copy(inFile,outFile) ;
?}
?public static boolean copy(File inFile,File outFile) throws Exception {
??InputStream input = null ; //实现输入数据读取
??OutputStream output = null ; //实现输出数据保存
??try {
???long start = System.currentTimeMillis() ;
???//需要考虑目标文件夹的生成问题
???if (!outFile.getParentFile().exists()){
????outFile.getParentFile().mkdirs() ;
???}
???//分别实例化输入流和输出流
???input = new FileInputStream(inFile) ;
???output = new FileOutputStream(outFile) ;
???int temp = 0 ; //保存每次读取进来的数据
???byte [] data = new byte [4096] ;
???//将数据读取到数组之中,而后返回读取的个数
???while ((temp = input.read(data)) != -1){
????output.write(data, 0, temp);
???}
???long end = System.currentTimeMillis() ;
???System.out.println("Time cost: " + (end - start));
???return true ;
??} catch (Exception e) {
???throw e ;
??} finally {
???if (input != null){
????input.close();
???}
???if (output != null){
????output.close();
???}
??}
?}
}