我从 gellery Intent.ACTION_SEND_MULTIPLE 意图中获得了多个 uri
我想要做的就是将这些文件复制到一个新位置“/sdcard/BACKUP/”我已经尝试了几个小时没有解决方案
这是代码:
ArrayList<Uri> imageUris = null;
if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
String root = Environment.getExternalStorageDirectory().getAbsolutePath()+"/";
File createDir = new File(root+"BACKUP"+File.separator);
if(!createDir.exists()) {
createDir.mkdir();
}
for (Uri uri : imageUris){
File file = new File(uri.getPath());
File newfile = new File(root + "BACKUP" + File.separator + uri.toString() +".jpg" );
copyFile(file,newfile);
}
private void copyFile(File sourceFile, File destFile) throws IOException {
if (!sourceFile.exists()) {
return;
}
FileChannel source = null;
FileChannel destination = null;
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
if (destination != null && source != null) {
destination.transferFrom(source, 0, source.size());
}
if (source != null) {
source.close();
}
if (destination != null) {
destination.close();
}
}
我得到一个 java.io.Filenotfound 异常