There are two common methods for database operations:
1. Create a database and a table in the Code. 2. directly create the relevant database and table and copy the db file to the assets Directory. Now let's take a look at the second method: private String GetDataBasePath (Context context) {String packageName = context. getPackageName (); // Log. I ("PackName", packageName); // String DB_PATH = String. format ("/data/% 1 $ s/databases/", // packageName); String DB_PATH = CommonData. baseDir + File. separator + DB_NAME; if (new File (DB_PATH )). exists () = false) {try {// For example, SQLite database file Does not exist. Check whether the database directory contains File f = new File (DB_PATH); // if the database directory does not exist, create this directory if (! F. exists () {f. mkdir ();} // get the prepared SQLite database under the assets directory as the input stream InputStream is = context. getAssets (). open (DB_NAME); // output stream OutputStream OS = new FileOutputStream (DB_PATH); // write byte [] buffer = new byte [1024]; int length; while (length = is. read (buffer)> 0) {OS. write (buffer, 0, length);} // close the file stream OS. flush (); OS. close (); is. close ();} catch (Exception e) {e. printStackTrace () ;}return DB_PATH ;}