import java.io.*;
/*
自定义缓冲区
*/
class MyBufferedInputStreamDemo
{
public static void main(String[] args) throws IOException
{
MyBufferedInputStream mis = new MyBufferedInputStream( new FileInputStream( new File("001.avi")));
BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream( new File("001-1.avi")));
int ch = 0;
while((ch=mis.read())!=-1)
{
bos.write(ch);
}
mis.close();
bos.close();
}
}
class MyBufferedInputStream
{
private InputStream inputStream = null;
private byte[] buffer = new byte[1024 * 4];
private int pos = 0,count=0;
public MyBufferedInputStream(InputStream inputStream) throws IOException
{
this.inputStream = inputStream;
}
public int read() throws IOException
{
// 如果结果长度为零,则从流中读取数据
if(count==0)
{
// 读取数据被放入字节数组中
count = this.inputStream.read(buffer);
// 如果读取的结果长度为-1,说明文件读取完成
if(count<0)
return -1;
// 每次重新从流中取数据时,将指针重置为0
pos = 0;
byte b = buffer[pos];
count--;
pos++;
return b&0xff;
}
else
{
byte b = buffer[pos];
count--;
pos++;
return b&0xff;
}
}
public void close() throws IOException
{
this.inputStream.close();
}
}
/*
自定义缓冲区
*/
class MyBufferedInputStreamDemo
{
public static void main(String[] args) throws IOException
{
MyBufferedInputStream mis = new MyBufferedInputStream( new FileInputStream( new File("001.avi")));
BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream( new File("001-1.avi")));
int ch = 0;
while((ch=mis.read())!=-1)
{
bos.write(ch);
}
mis.close();
bos.close();
}
}
class MyBufferedInputStream
{
private InputStream inputStream = null;
private byte[] buffer = new byte[1024 * 4];
private int pos = 0,count=0;
public MyBufferedInputStream(InputStream inputStream) throws IOException
{
this.inputStream = inputStream;
}
public int read() throws IOException
{
// 如果结果长度为零,则从流中读取数据
if(count==0)
{
// 读取数据被放入字节数组中
count = this.inputStream.read(buffer);
// 如果读取的结果长度为-1,说明文件读取完成
if(count<0)
return -1;
// 每次重新从流中取数据时,将指针重置为0
pos = 0;
byte b = buffer[pos];
count--;
pos++;
return b&0xff;
}
else
{
byte b = buffer[pos];
count--;
pos++;
return b&0xff;
}
}
public void close() throws IOException
{
this.inputStream.close();
}
}