import java.io.*;
class MyBufferedInputStream
{
private InputStream in;
private int pos = 0,count = 0;
private byte[] buf = new byte[1024];
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();
}
}
class MyBufferedInputStreamDemo
{
public static void main(String[] args)
{
long start = System.currentTimeMillis();
MyBufferedInputStream bis = null;
BufferedOutputStream bos = null;
try
{
bis = new MyBufferedInputStream (new FileInputStream("mp3.exe"));//错点
bos = new BufferedOutputStream (new FileOutputStream("mp32.exe"));
byte[] buf = new byte[1024];
int ch =0;
while((ch = bis.myRead(buf))!=-1)
{
bos.write(buf,0,ch);
}
}
catch (IOException e)
{
throw new RuntimeException("复制失败");
}
finally
{
try
{
if(bis != null)
bis.myClose();
}
catch (IOException e)
{
throw new RuntimeException("读取失败");
}
try
{
if(bos != null)
bos.close();
}
catch (IOException e)
{
throw new RuntimeException("读取失败");
}
}
long end = System.currentTimeMillis();
System.out.println((end-start)+"毫秒");
}
}
/*
E:\java\day19>javac MyBufferedInputStreamDemo.java
MyBufferedInputStreamDemo.java:74: 错误: 无法将类 MyBufferedInputStream中的方法
myRead应用到给定类型;
while((ch = bis.myRead(buf))!=-1)
^
需要: 没有参数
找到: byte[]
原因: 实际参数列表和形式参数列表长度不同
1 个错误
*/
|
|