title: How to backup sqlite database on internal storage
body: <p>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 <strong>HTC One X</strong></p>
  
  <p>I have also added one permission in manifest file</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  
  
  
  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;
      }
  </code></pre>
  
  <p>This is the error I am getting</p>
  
  <blockquote>
    <p>java.io.FileNotFoundException: /mnt/sdcard/appDb.db: open failed:
    EROFS (Read-only file system)</p>
  </blockquote>
  
  <p>Please guide as I want to store all my errors in the database so that we can Analyse them later.</p>
  
  <p>Thanks</p>