Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 22nd, 2012  |  syntax: None  |  size: 1.14 KB  |  hits: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Android - Can not find the file although it exists in the data folder?
  2. try {
  3.     File sd = Environment.getExternalStorageDirectory();
  4.     File data = Environment.getDataDirectory();
  5.  
  6.     if (sd.canWrite()) {
  7.         String currentDBPath = "\data\PackageName\databases\myDB.db";
  8.         String backupDBPath = "myDB.db";
  9.         File currentDB = new File(data, currentDBPath);
  10.         File backupDB = new File(sd, backupDBPath);
  11.  
  12.         if (currentDB.exists())
  13.         {
  14.            // code to copy from currentDB  to backupDB
  15.         }
  16.     }
  17. } catch (Exception e) {
  18. }
  19.        
  20. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
  21.        
  22. try
  23.  {
  24.     File sd = Environment.getExternalStorageDirectory();
  25.     File data = Environment.getDataDirectory();
  26.  
  27.     if (sd.canWrite()) {
  28.         String currentDBPath = "\data\PackageName\databases\myDB";
  29.         String backupDBPath = "myDB";
  30.         File currentDB = new File(data, currentDBPath);
  31.         File backupDB = new File(sd, backupDBPath);
  32.  
  33.         if (currentDB.exists())
  34.         {
  35.            // code to copy from currentDB  to backupDB
  36.         }
  37.     }
  38. } catch (Exception e) {
  39. }