黑马程序员技术交流社区
标题:
复制文件,大了1byte,求分析
[打印本页]
作者:
Adualtbird
时间:
2015-9-17 18:45
标题:
复制文件,大了1byte,求分析
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
class MyBufferedInputStream
{
private InputStream in;
private byte[] buf=new byte[1024];
private int count=0,pos=0;
MyBufferedInputStream(InputStream in){
this.in=in;
}
public int myRead()throws IOException
{
byte b=0;
if(count==0){
pos=0;
count=in.read(buf);
b=buf[pos];
count--;
pos++;
return b&255;
}else if(count>0)
{
b=buf[pos];
count--;
pos++;
return b&0xff;
}
return -1;
}
public void myClose()throws IOException
{
in.close();
}
}
class CopyMusic
{
public static void main(String[] args)throws IOException
{
MyBufferedInputStream mis=new MyBufferedInputStream(new FileInputStream("D:\\我想念你.mp3"));
BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream("D:\\CopyTestMusic.mp3"));
int len=0;
while((len=mis.myRead())!=-1){
bos.write(len);
}
mis.myClose();
bos.close();
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2