把D盘的复制到E盘,输入输出流

package p1;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class CopyTestDtoE {

public static void main(String[] args) {
String DoldPath=“D:\oo.docx”;
String EnewPath=“E:\”+System.nanoTime()+".docx";
copyFile(DoldPath,EnewPath);
}
private static void copyFile(String DoldPath, String EnewPath) {
FileInputStream fis=null;

FileOutputStream fos=null;
try {
fis=new FileInputStream(new File(DoldPath));
fos=new FileOutputStream(new File(EnewPath));

byte[] buff=new byte[1024];
int len;
long begintime = System.currentTimeMillis();//获取拷贝文件前的系统时间
while((len=fis.read(buff))!=-1){
fos.write(buff,0,len);
fos.flush();
}
long endtime = System.currentTimeMillis();//获取文件拷内结束时的系统时间
System.out.println(“拷贝文件所消耗的时间是:”+(endtime-begintime)+“毫秒”);
System.out.println(“复制完成”);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {

e.printStackTrace();
} finally{
try {
fos.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
把D盘的复制到E盘,输入输出流