import java.io.*;
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
{
//通过in对象读取硬盘上的数据,并存储buf中。
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();
}
}
class MyBufferedInputStreamDemo
{
public static void main(String[] args) throws IOException
{
MyBufferedInputStream bufis= new MyBufferedInputStream(new FileInputStream("d:\\真的不容易.mp3"));
BufferedOutputStream bufos = new BufferedOutputStream(new FileOutputStream("d:\\真的不容易(2).mp3"));
int len = 0;
while((len=bufis.myRead())!=-1)
{
bufos.write(len);
}
bufos.close();
bufis.myClose();
}
}
MyBufferedInputStream
最新推荐文章于 2021-10-19 10:59:46 发布