There is such an interview question:
How to publish the SQLite database (dictionary. db file) with the apk file?
A:Put this file in the/res/raw directory. Files in the res \ raw directory are not compressed, so that files in the directory can be extracted directly and the resource id is generated.
So how to import the database under the raw file to the database directory of the installed program?
Public void imporDatabase () {// database directory String dirPath = "/data/com. hkx. wan/databases "; File dir = new File (dirPath); if (! Dir. exists () {dir. mkdir () ;}// database File file = new File (dir, "abc. db"); try {if (! File. exists () {file. createNewFile ();} // load the database InputStream to be imported is = this. getApplicationContext (). getResources (). openRawResource (R. raw. db_weather); FileOutputStream fos = new FileOutputStream (file); byte [] buffere = new byte [is. available ()]; is. read (buffere); fos. write (buffere); is. close (); fos. close ();} catch (FileNotFoundException e) {e. printStackTrace ();} catch (IOException e) {e. printStackTrace ();}}