android 1.5,以编程方式将歌曲从/ sd卡/歌曲复制到/ sd卡/备份

时间:2011-04-06 04:49:16

标签: android backup mp3 android-sdcard

我正在使用eclipse模拟器,我想以编程方式将一些mp3从 / sdcard / songs 复制到 / sdcard / backup ,有没有办法这样做? 任何帮助和代码片段非常感谢! 谢谢! :)

1 个答案:

答案 0 :(得分: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) {}