FileInputStream fis = new FileInputStream("1.gif");
byte[] by = new byte[1024];
int len = 0;
while ((len = fis.read(by))!=-1)
{
fos.write(by,0,len);
}
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("1.gif"));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("copy1.gif"));
byte[] by = new byte[1024];
int len =0;
while ((len =bis.read(by))!=-1)
{
// bos.write(len);犯错
bos.write(by,0,len);
}
bis.close();
bos.close();
InputStream 可以自定义缓冲区 byte[] by = new byte[1024];而里面的1024可以是整数倍,而BufferedInputStream里面的内置缓冲区最大一次读8192个字节,他是先将8192个字节一个个读到他的内置缓冲区,然后再一次性的将8192个字节给java虚拟机,因为这8192个是在内存中操作,所以会很快的,然后程序处理完后,再一次行写出8192个到内置缓冲区,再一个一个写出操作,这样速度会很快的