0

SD カードに保存されている .3gp オーディオ ファイルがあります。そのファイルを SD カードの別のフォルダにコピーしたいと考えています。Google でいろいろ調べましたが、うまくいきませんでした。誰か知っていれば助けてください。今まで試したコードを以下に示します。

private void save(File file_save) {

    String file_path = Environment.getExternalStorageDirectory()
            .getAbsolutePath() + "/RecordedAudio";
    File file_dir = new File(file_path);
    if (file_dir.exists()) {
        file_dir.delete();
    }
    file_dir.mkdirs();
    File file_audio = new File(file_dir, "audio"
            + System.currentTimeMillis() + ".3gp");
    try {

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(bos);
        out.writeObject(file_save);
        out.close();
        FileOutputStream fos = new FileOutputStream(file_audio);

        byte[] buffer = bos.toByteArray();
        fos.write(buffer);

        fos.flush();
        fos.close();

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

これは常にサイズが 100 の新しいファイルを作成することです。よろしくお願いします... この save() メソッドを呼び出すときのコードは次のとおりです。

 mFileFirst = new File(mFileName);//mFileName is the path of sd card where .3gp file is located
    save(mFileFirst);
4

1 に答える 1

0

これを試して

private void save(File file_save) {
    String file_path = Environment.getExternalStorageDirectory()
            .getAbsolutePath() + "/RecordedAudio";
    File file_dir = new File(file_path);
    if (file_dir.exists()) {
        file_dir.delete();
    }
    file_dir.mkdirs();
    File file_audio = new File(file_dir, "audio"
            + System.currentTimeMillis() + ".3gp");
    try {

        FileInputStream fis = new FileInputStream(file_save);
        FileOutputStream fos = new FileOutputStream(file_audio);

        byte[] buf = new byte[1024];
        int len;
        int total = 0;
        while ((len = fis.read(buf)) > 0) {
            total += len;
            fos.write(buf, 0, len);
            // Flush the stream once every so often
            if (total > (20 * 1024)) {
                fos.flush();
            }
        }
        fos.flush();
        fis.close();
        fos.close();

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}
于 2013-05-06T07:47:32.563 に答える