本帖最后由 wangqing 于 2011-11-27 13:35 编辑
package com.day19;
import java.io.*;
import com.sun.org.apache.bcel.internal.generic.NEW;
public class MyBufferedInputStreamDemo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
class MyBufferedInputStream
{
private InputStream in;
private byte[] buf=new byte[1024];
private int pos=0,count=0;
MyBufferedInputStream(InputStream in)
{
this.in=in;
}
public int myRead()throws IOException
{
if(count==0)
{
count=in.read(buf);
if(count<0)
return -1;
pos=0;
byte b=buf[pos];
count--;
pos++;
return b&255;
}
else if(count>0)
{
byte b=buf[pos];
count--;
pos++;
return b&255;
}
return -1;
}
public void myClose()throws IOException
{
in.close();
}
}
为什么myRead()方法返回的类型是int,还是不明白,求高手指点。 |