
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/*
* 字节流复制文件
* 采用数组缓冲提升效率
* 字节数组
* FileInputStream读取字节数组
* FileOutputStream写入字节数组
*/
public class cope {
public static void main(String[] args) {
// TODO Auto-generated method stub
FileInputStream fis = null;
FileOutputStream fos = null;
long s = System.currentTimeMillis();//运行开始的时间,以毫秒为单位
try {
fis = new FileInputStream("C:a.txt");
fis = new FileInputStream("C:a.txt");
// 定义数组,缓冲
byte[] bytes = new byte[1024];
// 读取数组,写入数组
while((fis.read(bytes)) != -1) {
fos.write(bytes);
}
}catch(IOException ex){
System.out .println(ex);
throw new RuntimeException("文件复制失败");
}finally {
try {
if(fos!=null)
fos.close();
}catch(IOException ex) {
throw new RuntimeException("释放资源失败");
}
finally {
try {
if(fis!=null)
fis.close();
}catch(IOException ex) {
throw new RuntimeException("释放资源失败");
}
}
}
long e = System.currentTimeMillis();//运行结束时间,1毫秒 = 0.001秒
System.out .println(e-s);
}
}