我试图在 Android 路径出现时复制该文件,但没有成功,尽管它已经作为 AndroidManifest 上的权限存在,就好像该文件不存在或在那里不知道它一样。这是一段代码:
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == RESULT_OK) {
Uri uri = data.getData();
String origem = uri.getPath();
File src = new File(origem);
if(src.isFile()){
Log.d(TAG,src.toString());
}
File root = Environment.getExternalStorageDirectory();
root = new File(root.toString(), "Kcollector/importa/import.csv");
try {
copy(src,root,true);
} catch (IOException e) {
e.printStackTrace();
}
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
public static void copy(File origem, File destino, boolean overwrite) throws IOException{
Date date = new Date();
if (destino.exists() && !overwrite){
System.err.println(destino.getName()+" já existe, ignorando...");
return;
}
FileInputStream fisOrigem = new FileInputStream(origem);
FileOutputStream fisDestino = new FileOutputStream(destino);
FileChannel fcOrigem = fisOrigem.getChannel();
FileChannel fcDestino = fisDestino.getChannel();
fcOrigem.transferTo(0, fcOrigem.size(), fcDestino);
fisOrigem.close();
fisDestino.close();
Long time = new Date().getTime() - date.getTime();
System.out.println("Saiu copy"+time);
}
尝试复制时返回的错误:
W/System.err:java.io.FileNotFoundException:/external_storage/Kcollector/importa/kvendasajustado.csv(没有这样的文件或目录) W/System.err:在 java.io.FileInputStream.open0(本机方法)
偶然的你
相关分类