import java.io.*;
class MyBufferedInputStream
{
private FileInputStream in;
private int count=0,pose=0;
private byte [] buf=new byte[1024];
MyBufferedInputStream(FileInputStream in)
{
this.in=in;
}
public int myRead() throws IOException
{
if(count==0)
{
count=in.read(buf);
System.out.println(count);
if(count<0)
{
//System.out.println("over");
return -1;
}
pose=0;//让数组指针回到初始位置!
byte b=buf[pose];
count--;
pose++;
return b&0xff;
}
//else
if(count>0)
{
byte b=buf[pose];
pose++;
count--;
return b&0xff;
}
return -1;
}
public void myClose() throws IOException
{
in.close();
}
}
class MyBufferedInputStreamCopyMp3
{
public static void main(String[] args) throws IOException
{
Long start=System.currentTimeMillis();
copyMp3();
Long end=System.currentTimeMillis();
System.out.println("拷贝MP3用时:"+(end-start)+"毫秒");
}
public static void copyMp3()throws IOException
{
BufferedOutputStream bos=
new BufferedOutputStream(new FileOutputStream("C:\\Users\\dell\\Desktop\\我是传奇_copy.mp3"));
MyBufferedInputStream mybis=
new MyBufferedInputStream(new FileInputStream("C:\\Users\\dell\\Desktop\\我是传奇_copy.mp3"));
int by=0;
//System.out.println(mybis.myRead());
while((by=mybis.myRead())!=-1)
{
bos.write(by);
}
mybis.myClose();
bos.close();
}
}
运行没有结果:读不出数据,懂的朋友指点一下!
|
|