java学习笔记 i/o

2017-06-08  本文已影响0人  rochuan

java在读取大文件上尽量使用缓冲流并且合理配置缓冲流大小这样性能会大大升高。

try{

FileInputStream fis =newFileInputStream("/Users/rochuan/Downloads/timg.jpeg");

FileOutputStream fos =newFileOutputStream("timg.jpeg");

BufferedInputStream bis =newBufferedInputStream(fis);

BufferedOutputStream bos =newBufferedOutputStream(fos);

byte[] b =new byte[10];

while(bis.read(b) != -1){

bos.write(b);

}

bos.close();

bis.close();

fis.close();

fos.close();

System.out.println("done!");

}catch(Exception e){

System.out.println(e.fillInStackTrace());

}

上一篇 下一篇

猜你喜欢

热点阅读