在SD卡中移动/重命名文件

我正在尝试将文件从一个目录移动到另一个目录(在SD卡中)

我有一个文件的URI和我试图移动它的方式:

Uri selectedImage = imageReturnedIntent.getData(); // this the uri, something like content://media/external/images/media/635 File sdcard = Environment.getExternalStorageDirectory(); File from = new File(sdcard, selectedImage); File to = new File(sdcard, "myNewDir/mynewfile.jpg"); from.renameTo(to); 

但它不起作用,它也没有给我在Logcat中的任何错误…

编辑:

我已将两个权限添加到我的清单文件中:

    

 // this the uri, something like content://media/external/images/media/635 

你正在做的是尝试将它连接到Environment.getExternalStorageDirectory() 。 这不行。 content://media/external/images/media/635既不是相对文件系统路径也不是绝对文件系统路径。 这是一个Uri

如果要将映像从Uri复制到本地文件,请使用ContentResolverUri表示的映像上获取InputStream ,然后使用Java I / O将InputStream的字节复制到目标文件。