如何在Android中以编程方式将图像文件从库复制到另一个文件夹 [英] How to Copy Image File from Gallery to another folder programmatically in Android

查看:122
本文介绍了如何在Android中以编程方式将图像文件从库复制到另一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从图库中挑选图像并将其复制到SDCard的其他文件夹中.

I want to pick image from gallery and copy it in to other folder in SDCard.

从图库中选取图片的代码

Code to Pick Image from Gallery

Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
    photoPickerIntent.setType("image/*");
    startActivityForResult(photoPickerIntent, REQUEST_CODE_CHOOSE_PICTURE_FROM_GALLARY);

我从content://media/external/images/media/681这个URI onActivityResult中获得了

I get content://media/external/images/media/681 this URI onActivityResult.

我要复制图像,

表格path ="content://media/external/images/media/681

在Android中sdcard的path = "file:///mnt/sdcard/sharedresources/路径.

To path = "file:///mnt/sdcard/sharedresources/ this path of sdcard in Android.

该怎么做?

推荐答案

OutputStream out;
            String root = Environment.getExternalStorageDirectory().getAbsolutePath()+"/";
            File createDir = new File(root+"Folder Name"+File.separator);
            if(!createDir.exists()) {
                createDir.mkdir();
            }
            File file = new File(root + "Folder Name" + File.separator +"Name of File");
            file.createNewFile();
            out = new FileOutputStream(file);                       

        out.write(data);
        out.close();

希望对您有帮助

这篇关于如何在Android中以编程方式将图像文件从库复制到另一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆