我困在這個小複雜的情況。我正在編寫android應用程序的一部分,我正在讀取一個Mp3文件到多個字節數組中。問題是這個字節數組的數量將由來自USB的文本文件以及每個字節數組的大小決定。 請給我一個出路。如何用不同的名稱和不同的大小動態創建字節數組?
下面是我的代碼,我正在讀MP3文件
cxt = ControlUnit.getAppContext();
try {
File file = new File("/mnt/media/USBDISK1/IFrame_00.bin");
input = new BufferedInputStream(new FileInputStream(file));
//input = cxt.getAssets().open("Maid with the Flaxen Hair.mp3");
Log.i("TvPlayerFunctionalTestApp", "mp3 file Read from Assests");
} catch (IOException e) {
// TODO Auto-generated catch block
Log.i("TvPlayerFunctionalTestApp", "Error in Opening mp3 File");
e.printStackTrace();
}
try {
size = input.available();
Log.i("TvPlayerFunctionalTestApp", "Size of Bin File: "+size);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
buffer = new byte[AClipTextFileHandler.BufferSize.get(0)];
input.read(buffer);
// input.read(buffer, offset, length);
Log.i("TvPlayerFunctionalTestApp", "buffer: "+ Arrays.toString(buffer));
buffer1 = new byte[AClipTextFileHandler.BufferSize.get(1)];
input.read(buffer1);
Log.i("TvPlayerFunctionalTestApp", "buffer: "+ Arrays.toString(buffer1));
StringBuffer stringBuff = new StringBuffer();
for (byte b:buffer)
{
stringBuff.append(String.format("%x", b));
}
Log.i("TvPlayerFunctionalTestApp","buffer: "+stringBuff) ;
for (byte b:buffer1)
{
stringBuff.append(String.format("%x", b));
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.i("TvPlayerFunctionalTestApp", "Error in Read");
}
try {
input.close();
Log.i("TvPlayerFunctionalTestApp", "File closed");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我無法理解如何List<Byte> arrays = new ArrayList<Byte>()
能幫助我。
如果你想有一個字節數組列表,使用'List arrays = new ArrayList ()'。 'byte []'是一個字節數組,但它不是一個基元,可以在泛型中使用。 –
gunar
int TotalBuffer = AClipTextFileHandler.BufferID.get(0); \t \t \t而(TotalBuffer!= 0){ \t \t \t bufferData [I] =新的字節[AClipTextFileHandler.BufferSize.get(J)]; \t \t \t input.read(bufferData [i]); \t \t \t i ++; \t \t \t j ++; \t \t \t TotalBuffer--; – SajidKhan