package day19;
import java.io.*;
public class MyBufferedCopyDemo
{
public static void main(String[] args) throws IOException
{
BufferedCopy1();
}
public static void BufferedCopy1() throws IOException
{
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("e:\\33.mp3"));
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("e:\\22.mp3"));
int ch = 0;
while((ch=bis.read())!=-1)
{
bos.write(ch);
}
bos.close();
bis.close();
}
}
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);
byte b =buf[pos];
count--;
pos++;
return b;
}
else if(count>0)
{
byte b =buf[pos];
count--;
pos++;
return b;
}
return -1;
}
public void myClose()throws IOException
{
in.close();
}
}
|
|