我们先上一个字节输入输出流的复制文件,代码:
public static void main(String[] args) {
FileInputStream in = null;
FileOutputStream o = null;
long s = System.currentTimeMillis();
try {
in = new FileInputStream("F:\\a\\Sams teach yourself SQL in 10 minutes,4th edition.pdf");
o = new FileOutputStream("f:\\a\\1.pdf");
byte[] b = new byte[1024*5];
int len = 0;
while((len =in.read(b))!=-1) {
o.write(b);
}
}catch(IOException e) {
System.out.println("文件写入失败!");
}finally {
try {
o.close();
}catch(IOException e) {
System.out.println("文件关闭失败!");
}finally {
try {
in.close();
}catch(IOException e) {
System.out.println("文件关闭失败");
}
}
}
long e = System.currentTimeMillis();
System.out.println(e-s);
}
in = new FileInputStream("F:\\a\\