package test2;标签:fos,缓冲,bos,printStackTrace,Demon01,new,null,bis From: https://www.cnblogs.com/Leizi-go/p/17356853.html
import java.io.*;
//缓冲流
public class Demo02 {
public static void main(String[] args) {
FileInputStream fis = null;
FileOutputStream fos = null;
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
fis = new FileInputStream("H:\\src.png");
fos = new FileOutputStream("H:\\target.png");
bis = new BufferedInputStream(fis);
bos = new BufferedOutputStream(fos);
int readData;
long start = System.currentTimeMillis();
while ((readData = bis.read()) != -1) {
bos.write((char)readData);
}
long end = System.currentTimeMillis();
System.out.println("运行时间:" + (end - start));
fos.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (bos != null) {
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}