Android 如何压缩2个文件

Android 如何压缩2个文件,android,performance,file,concat,Android,Performance,File,Concat,我怎样才能找到两个文件 我有两个音频部分(每个部分包含来自同一来源的大约3秒钟的音频)。 我正在尝试合并这两个文件并用android mediaplayer播放主题。 目前我正在使用下面的方法,虽然效果很好,但需要很多时间(在我的galaxy nexus上大约13秒) 所以我的问题是,有没有办法更快地做到这一点 public static void merge(File audioFile1, File audioFile2, File outputFile){ long time

我怎样才能找到两个文件

我有两个音频部分(每个部分包含来自同一来源的大约3秒钟的音频)。 我正在尝试合并这两个文件并用android mediaplayer播放主题。 目前我正在使用下面的方法,虽然效果很好,但需要很多时间(在我的galaxy nexus上大约13秒)

所以我的问题是,有没有办法更快地做到这一点

   public static void merge(File audioFile1, File audioFile2, File outputFile){
    long timeStart= System.currentTimeMillis();
    try {

        FileInputStream fistream1 = new FileInputStream(audioFile1);
        FileInputStream fistream2 = new FileInputStream(audioFile2);
        SequenceInputStream sistream = new SequenceInputStream(fistream1, fistream2);
        FileOutputStream fostream = new FileOutputStream(outputFile);

        int temp;

        while( ( temp = sistream.read() ) != -1)
        {

            fostream.write(temp);  
        }

        fostream.close();
        sistream.close();
        fistream1.close();          
        fistream2.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    long timeEnd= System.currentTimeMillis();

    Log.e("merge timer:", "milli seconds:" + (timeEnd - timeStart));
}
替换

int temp;
while((temp = sistream.read()) != -1) {
    fostream.write(temp);  
}
对于缓冲副本:

int count;
byte[] temp = new byte[4096];
while((count = sistream.read(temp)) != -1) {
    fostream.write(temp, 0, count);  
}
一次最多读取4096个字节,而不是一次读取1个字节


BufferedReader
/
BufferedWriter
可能会进一步提高性能。

Thnx很多。当我像你提到的那样设置缓冲区时,只需要17毫秒。我将检查BufferedReader/BufferedWriter,但我认为这将足够好地完成这项工作:)。