我真的需要一些帮助。我想合并两个音频文件,并将单个音频文件设为.mp3 我想我们可以在获取字节后合并两个文件,但我不确定它是否可行。 我需要一些适当的解决方案来做到这一点
答案 0 :(得分: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.!");
}