在自定义的MyBufferedStream类中进行判断的if···else语句,我认为去掉else这部分判断也行啊。
import java.io.*;
public class FileReaderDemo11 {
public static void main(String[] args)throws IOException{
MyBufferedStream mybuf = new MyBufferedStream(new FileInputStream("D:\\歌词\\新Atomic Kitten-Nothing In The World.mp3"));
BufferedOutputStream bfo = new BufferedOutputStream(new FileOutputStream("C:\\hah.mp3"));
int ch;
while((ch=mybuf.myRead())!=-1){
bfo.write((char)ch);
}
mybuf.myClose();
bfo.close();
}
}
class MyBufferedStream{
private FileInputStream fs;
private int num = 0, pos =0;
private byte[] ch = new byte[1024];
MyBufferedStream(FileInputStream fs){
this.fs = fs;
}
public int myRead() throws IOException{
if(num==0){
num =fs.read(ch);
if(num<0){
return -1;
}
pos = 0;
byte b = ch[pos];
pos++;
num--;
return b&0xff;
}else if(num >0){
byte b = ch[pos];
pos++;
num--;
return b&0xff;
}//该红色区域能否去除????
return -1;
}
public void myClose()throws IOException{
fs.close();
}
}
|
|