class MyBufferedInputStream {
private InputStream in;
private byte[] buf = new byte[1024*4];
int pos = 0,count = 0;
MyBufferedInputStream(InputStream in){
this.in = in;
}
public int myRead(){
if(count==0){
try {
count = in.read(buf);
} catch (IOException e) {
e.printStackTrace();
}
if(count<0){
return -1;
}
pos = 0;
byte b = buf[pos];
count--;
pos++;
return b&255;
}else if(count>0){
pos = 0;
byte b = buf[pos];
count--;
pos++;
return b&0xff;
}
return -1;
}
}
用这个自定义BufferedInputStream复制文件,文件老是没有复制全,这个程序有什么问题吗?谢谢
|