title: Backup /data/system/xxxx.bin to /sdcard
body: <p>I'm fairly new to apk development. So far, after a book purchase and with a lot of Googling I've managed to make an application that controls some features of my custom ROM. I'm currently trying to implement 2 backup features. I want to backup /data/system/batterystats.bin to /sdcard and also i want to backup launcher.db of my touchwiz launcher to /sdcard.</p>
  
  <p>For the first part i haven't actually found anything. I've searched a lot about how to restore a file, not much has come up. It's mostly about SQL .db files. I've also looked for the possibility to run a shell script via the apk just to perform this backup. With a shell script it's easy work, but doing this via .java, i honestly have no clue.</p>
  
  <p>Also, i've tried quite a lot of code to get my sqlite database file to backup, but i was quite unsuccessful. Here's my code for you to look at:</p>
  
  <pre><code>public class Backup extends Activity {
  public void exportDB(){
      try {
          File sd = Environment.getExternalStorageDirectory();
          if (sd.canWrite()) {
              String currentDBPath = "data/data/com.sec.android.app.twlauncher/databases/launcher.db";
              String backupDBPath = sd + "/launcher.db";
              File currentDB = new File(currentDBPath);
              File backupDB = new File(backupDBPath);
  
              if (currentDB.exists()) {
                  FileChannel src = new FileInputStream(currentDB).getChannel();
                  FileChannel dst = new FileOutputStream(backupDB).getChannel();
                  dst.transferFrom(src, 0, src.size());
                  src.close();
                  dst.close();
                  }
          }
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I have added permissions for external storage write, of course in the androidmanifest, but nothing happens. No FC, it just sits there doing nothing. And when I check my sdcard, there's nothing there.</p>
  
  <p>Any help would be greatly appreciated. Thanks</p>