I'm trying to create a copy of the sd memory, but the procedure I do does not do anything or I get an error, I have the write permissions, this is the code I'm implementing
public static boolean copyFile(String from, String to) {
boolean result = false;
try{
File dir = new File(to.substring(0, to.lastIndexOf('/')));
dir.mkdirs();
File tof = new File(dir, to.substring(to.lastIndexOf('/') + 1));
int byteread;
File oldfile = new File(from);
if(oldfile.exists()){
// System.exit(0);
InputStream inStream = new FileInputStream(from);
FileOutputStream fs = new FileOutputStream(tof);
byte[] buffer = new byte[1024];
while((byteread = inStream.read(buffer)) != -1){
fs.write(buffer, 0, byteread);
}
inStream.close();
fs.close();
}
result = true;
}catch (Exception e){
Log.e("copyFile", "Error copiando archivo: " + e.getMessage());
}
return result;
}
from here I call the procedure
String nombd = "DBUsuarios";
//Obtiene ruta de base de datos origen.
String pathDB = getDatabasePath(nombd).toString();
//Copia base de datos a destino definido.
copyFile(pathDB,""+Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS));
Permissions
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />