android 1.5,以编程方式将歌曲从 /sdcard/songs 复制到 /sdcard/backup

发布于 2024-10-30 19:22:29 字数 142 浏览 10 评论 0原文

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

i am using eclipse emulator and i want to copy programmatically some mp3s from /sdcard/songs to /sdcard/backup, is there any way to do so?
any help and code snippet is greatly appreciated!
thanks! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

世态炎凉 2024-11-06 19:22:29

你可以试试这个:

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) {}

You can try this:

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) {}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文