缓冲流Demon01

发布时间 2023-04-26 17:52:40作者: 磊子记
package test2;

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();
}
}
}


}

}