我真的需要一些帮助。我想合并两个音频文件并将单个音频文件制作为 .mp3 我认为我们可以在获取它们的字节后合并两个文件,但我不确定它是否会起作用。我需要一些适当的解决方案来做到这一点
问问题
1127 次
1 回答
0
嗨看看下面的代码可能对你有帮助
public void mergeParts ( ArrayList<String> nameList, String DESTINATION_PATH )
{
File[] file = new File[nameList.size()];
byte AllFilesContent[] = null;
int TOTAL_SIZE = 0;
int FILE_NUMBER = nameList.size();
int FILE_LENGTH = 0;
int CURRENT_LENGTH=0;
for ( int i=0; i<FILE_NUMBER; i++)
{
file[i] = new File (nameList.get(i));
TOTAL_SIZE+=file[i].length();
}
try {
AllFilesContent= new byte[TOTAL_SIZE]; // Length of All Files, Total Size
InputStream inStream = null;
for ( int j=0; j<FILE_NUMBER; j++)
{
inStream = new BufferedInputStream ( new FileInputStream( file[j] ));
FILE_LENGTH = (int) file[j].length();
inStream.read(AllFilesContent, CURRENT_LENGTH, FILE_LENGTH);
CURRENT_LENGTH+=FILE_LENGTH;
inStream.close();
}
}
catch (FileNotFoundException e)
{
System.out.println("File not found " + e);
}
catch (IOException ioe)
{
System.out.println("Exception while reading the file " + ioe);
}
finally
{
write (AllFilesContent,DESTINATION_PATH);
}
System.out.println("Merge was executed successfully.!");
}
于 2012-12-28T12:17:19.900 回答