第四次作业
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class copy {
public static void main(String[] args) {
FileOutputStream outputStream;
try {
FileOutputStream os = new FileOutputStream("b.mp3",true);
FileInputStream is = new FileInputStream("a.mp3");
DataInputStream d = new DataInputStream(is);
DataOutputStream a = new DataOutputStream(os);
byte []b = new byte[1024];
int length = d.read(b);
while(length!=-1){
a.write(b,0,length);
length = d.read(b);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
源代码复制速度慢,一个中文需要两个字节,而改进后的二进制流很大提升了速率。