java - android copy database from assets folder -


i having trouble coping database assets folder databases folder. when user start application check if database doesnt exists , if true copy database.

where code:

    private void copydatabaseifnotexists() {          dbname = "quizdb.db";          file f = getdatabasepath(dbname);         if (f.exists())             return;          system.out.println("db missing");          try {              inputstream minputstream = getassets().open(dbname);              outputstream moutputstream = new fileoutputstream(f);             byte[] buffer = new byte[1024];             int length;             while ((length = minputstream.read(buffer)) > 0) {                 moutputstream.write(buffer, 0, length);             }             moutputstream.flush();             moutputstream.close();             minputstream.close();          } catch (nullpointerexception e) {             e.printstacktrace();         } catch (filenotfoundexception e) {             e.printstacktrace();         } catch (exception e) {             e.printstacktrace();         }     } 

and got error:

06-15 12:29:04.882  25037-25037/com.ex.example w/system.err﹕ java.io.filenotfoundexception: /data/data/com.ex.example/databases/quizdb.db: open failed: enoent (no such file or directory) 

i tried search soluction cant find. can me? , sorry english.

fileoutputstream throws exception when file not exist and cannot created. had probelm before , managed solve first calling openorcreatedatabase method of context object (or sqlitedatabase class) before outputstream moutputstream = new fileoutputstream(f);


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -