2

私は Eclipse エミュレーターを使用しており、いくつかの mp3 をプログラムで/sdcard/songsから/sdcard/backupにコピーしたいのですが、そうする方法はありますか? ヘルプとコードスニペットは大歓迎です! ありがとう!:)

4

1 に答える 1

6

これを試すことができます:

try {
    File sd = Environment.getExternalStorageDirectory();

    if (sd.canWrite()) {
        String sourcePath= "/path/to/source/file.mp3";
        String destinationPath= "/path/to/destination/file.mp3";
        File source= new File(sd, sourcePath);
        File destination= new File(sd, destinationPath);
        if (source.exists()) {
            FileChannel src = new FileInputStream(source).getChannel();
            FileChannel dst = new FileOutputStream(destination).getChannel();
            dst.transferFrom(src, 0, src.size());
            src.close();
            dst.close();
        }
} catch (Exception e) {}
于 2011-04-06T04:57:49.543 に答える