I'm trying to copy the file as the Android path comes, without success, although it already existed as permissions on AndroidManifest, it's as if the file did not exist or know it there. Here's a piece of code:
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);
}
The error that returns me when trying to copy:
W/System.err: java.io.FileNotFoundException: /external_storage/Kcollector/importa/kvendasajustado.csv (No such file or directory) W/System.err: at java.io.FileInputStream.open0(Native Method)