package com.xjtu.demo;
import java.io.*;
public class FileCopy {
public static void main(String[] args) throws Exception {
long start = System.currentTimeMillis();
if (args.length != 2) { //参数不足
System.out.println("命令语法错误");
System.exit(1);
}
File inFile = new File(args[0]); //源文件路径
if (!inFile.exists()) {
System.out.println("源文件不存在");
System.exit(1);
}
File outFile = new File(args[1]); //目标文件
if(!outFile.getParentFile().exists()) {
outFile.getParentFile().mkdirs();
}
byte data[] = new byte [2048];
InputStream input = new FileInputStream(inFile); //输入流
OutputStream output = new FileOutputStream(outFile); //输出流
int temp = 0; //接收每次读取的内容
while((temp = input.read(data)) != -1) { //有内容可读
output.write(data,0,temp); //输出内容
}
input.close();
output.close();
long end = System.currentTimeMillis();
System.out.println( "用时"+ (end-start));
}
}