title: Can't copy SQLite database from assets
body: <p>I try to copy SQLite database from assets directory to access it later. But I fail to do it!</p>
  
  <pre><code>public class DatabaseAdapter {
      private static String DB_PATH = "/data/data/com.mypackage/databases/";
      private static String DB_NAME = "database.sqlite";
      private static String TABLE_NAME = "content_table";
  
      private SQLiteDatabase database = null;
      private final Context context;
  
      public DatabaseAdapter(Context context){
          this.context = context;
      }
  
      private void openDatabase() throws SQLiteException{
          DatabaseHelper databaseHelper = new DatabaseHelper(context, DB_NAME);
          SQLiteDatabase db = null;
          if(!checkDatabase()){
              try{
                  //Tried to create db before copying, so file should exist
                  db = databaseHelper.getReadableDatabase();
                  db.close();
  
                  copyDatabase();
  
              }catch(IOException exception){
                  Log.d("DatabaseAdapter", "Error copying DB: "+exception);
              }
          }
  
          database = SQLiteDatabase.openDatabase(DB_PATH+DB_NAME, null, SQLiteDatabase.OPEN_READONLY);
      }
  
      private void closeDatabase(){
          database.close();
      }
  
      public ArrayList&lt;String&gt; queryCategories(){
          try{
              openDatabase();
          }catch(SQLiteException exc){
              exc.printStackTrace();
          }
          //.............................
          return result;
      }
  
      private boolean checkDatabase(){
          File dbFile = new File(DB_PATH + DB_NAME);
          return dbFile.exists();
      }
  
      private void copyDatabase() throws IOException{
          InputStream inputStream = context.getAssets().open(DB_NAME);
  
          String outFileName = DB_PATH + DB_NAME;
  
          OutputStream outputStream = new FileOutputStream(outFileName);
  
          byte[] buffer = new byte[1024];
          int length;
          while ((length = inputStream.read(buffer))&gt;0){
              outputStream.write(buffer, 0, length);
          }
  
          outputStream.flush();
          outputStream.close();
          inputStream.close();
      }
  
  }
  </code></pre>
  
  <p>DatabaseHelper is simple:</p>
  
  <pre><code>ublic class DatabaseHelper extends SQLiteOpenHelper {
  
      public DatabaseHelper(Context context, String name){
          super(context, name, null, 1);
  
      }
  
  
      @Override
      public void onCreate(SQLiteDatabase arg0) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
          // TODO Auto-generated method stub
  
      }
  
  }
  </code></pre>
  
  <p>Tried everything! I tried playing with extention! But I still get an error: 
  Error copying DB: <code>java.io.FileNotFoundException: /data/data/com.mypackage/databases/database.sqlite (No such file or directory)</code></p>
  
  <p>I checked on emulator, my file is there, so I should be able to write to it!
  Please, any help! It's driving me nuts!</p>
  
  <p><strong>UPD</strong> I tried to place it on SD card and it worked. But still can't get why I can't write it to app data folder.</p>