问题描述:今天一敲代码,怎么感觉字节流中的字节数组为什么不能读取到,反而比原图片的字节大好多倍??
代码如下:
public static void copyPic1()throws IOException{
//我就不try了
FileInputStream in = new FileInputStream("c:\\clone.bmp");
FileOutputStream out = new FileOutputStream("c:\\bp.bmp");
byte[] by = new byte[1024];
int len = 0;
while((len=in.read())!=-1){
out.write(by,0,len);
// out.write(len); 注释掉byte数组,图片就写入成功
}
out.close();
in.close();
}
public static void copyPic2()throws IOException{
//我就不try了
BufferedInputStream bufin = new BufferedInputStream(new FileInputStream("c:\\clone.bmp"));
BufferedOutputStream bufout = new BufferedOutputStream(new FileOutputStream("c:\\pp.bmp"));
// byte[] by = new byte[1024];
int len = 0;
while((len=bufin.read())!=-1){
// bufout.write(by,0,len); 字节缓冲字节流也是如此,
bufout.write(len);
}
bufout.close();
bufin.close();
}
问题:1)把读取到字节缓存到byte[]里,和直接读取后,为什么缓存的数据就比原来的数据量大,导致的直接原因是什么?
2)若果不加缓冲流的话,输入(in)输出(out)关闭的顺序,我从IO这块的理解是,不加缓冲技术,应该就是即读即写的这种,首先关闭的是写,再关闭读取流,但感觉效率的影响又不是很大!即他们的关闭顺序的区别有吗?