public class Test {
public static void main(String[] args) {
long start = System.currentTimeMillis();
FileOutputStream fos = null;
FileInputStream fis = null;
try {
//创建文件的字节输入流对象,即源文件路径
fis = new FileInputStream("D:\\XXX.docx");
//创建字节的输出流对象,命名新的文件名
fos = new FileOutputStream("XXX.docx");
int i = 0;
while (true) {
//一次一个字节读和写,效率低
if ((i = fis.read()) != -1) {
fos.write(i);
} else {
break;
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
//关闭输入输出流
if (null != fis) {
fis.close();
}
if (fos != null) {
fos.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
long end=System.currentTimeMillis();
//计算所用时间
System.out.println(end-start);
}
}