3
我正在android中工作。我想合併兩個wave文件並想創建第三個文件。爲此,我創建兩個輸入流,然後嘗試將這些輸入流寫入一個輸出流文件。Android無法合併兩個wave文件
這是我的代碼: -
File file = new File("/sdcard/z.wav");
File file1 = new File("/sdcard/zz.wav");
InputStream is = new FileInputStream(file);
InputStream is1 = new FileInputStream(file1);
// Get the size of the file
long length = file.length();
long length1 = file1.length();
// Create the byte array to hold the data
byte[] bytes = new byte[(int)length];
byte[] bytes1 = new byte[(int)length1];
// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < (int)length &&(numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
}
int offset1 = 0;
int numRead1 = 0;
while (offset1 < (int)length1 &&(numRead1=is1.read(bytes1, offset1, bytes1.length-offset1)) >= 0) {
offset1 += numRead1;
}
FileOutputStream fos=new FileOutputStream("sdcard/guruu.wav");
Log.v("Trying Activity","before first write");
fos.write(bytes);
fos.write(bytes1,0,bytes1.length);
fos.write(bytes);
fos.close();
is.close();
is1.close();
當我玩輸出文件guruu.wav那麼文件1這只是播放文件,它是不是在玩file2的內容。請告訴我我做了什麼錯誤。有沒有其他方法可以做到這一點?
我很新,所以請不要投票。
預先感謝您。