I am using this below code to copy my database to internal storage but it is not helping me out and always getting this error. I have gone through lots of questions and answers and tried lots of blog posts but am unable to make it work. My phone is HTC One X
I have also added one permission in manifest file
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
public static boolean backUpDataBase(Context context)
{
String packageName = "com.projectWork.mobile";
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (Environment.MEDIA_MOUNTED.equals(sd))
{
String currentDBPath = "//data//"+ packageName +"//databases//"+"appDb.db";
String backupDBPath = "appDb.db";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
Toast.makeText(context, backupDB.toString(), Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
}
return true;
}
This is the error I am getting
java.io.FileNotFoundException: /mnt/sdcard/appDb.db: open failed: EROFS (Read-only file system)
Please guide as I want to store all my errors in the database so that we can Analyse them later.
Thanks