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 回答