拷贝的图片少了100多个字节,代码如下,请大虾看看哪边有问题
- import java.io.*;
- class MyBufferedInputStreamDemo
- {
- public static void main(String[] args) throws IOException
- {
- MyBufferedInputStream bis = new MyBufferedInputStream(new FileInputStream("touxiang.jpg"));
- BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("copy2.jpg"));
- int b = 0;
- while((b=bis.read())!=-1){
- bos.write(b);
- }
- bis.close();
- bos.close();
- }
- }
- class MyBufferedInputStream
- {
- private InputStream is;
- private byte[] buf = new byte[1024];
- private int pos=0,count=0;
- public MyBufferedInputStream(InputStream is){
- this.is = is;
- }
- public int read()throws IOException{
- if(count ==0){
- count = is.read(buf);
- if(count==-1)
- return -1;
- pos = 0;
- }
- count--;
- return buf[pos++]&255;
- }
- public void close()throws IOException{
- is.close();
- }
- }
复制代码
|