字节流:
字节流是面向字节的流,流中的数据以8位字节为单位进行读写,是象类InputStream和OutputString的子类,通常用来读写二进制数据,如图像和声音。
字符流:
字符流是面向字符的流,流中的数据以16位字符为单位进行读写而。字符流是抽象类Reader和Writer的子类。
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 fuzhi {
public static void main(String[] args) {
FileOutputStream outputStream;
try {
outputStream = new FileOutputStream("b.mp3",true);
FileInputStream inputStream = new FileInputStream("a.mp3");
DataInputStream dataInput = new DataInputStream(inputStream);
DataOutputStream dataOutput = new DataOutputStream(outputStream);
byte []wxj = new byte[1024];
int length = dataInput.read(wxj);
while(length!=-1){
dataOutput.write(wxj,0,length);
length = dataInput.read(wxj);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}