There are two common ways to operate on a database:
1, in the code to build a library, build a table;
2, directly set up the relevant libraries, tables, copy the DB file to the assets directory;
Now let's look at the second method:
Privatestring Getdatabasepath (Context context) {string PackageName=Context.getpackagename (); //log.i ("Packname", PackageName); //String Db_path = String.Format ("/data/data/%1$s/databases/",//packagename);String Db_path = commondata.basedir + File.separator +db_name; if((NewFile (Db_path)). Exists () = =false) { Try { //if the SQLite database file does not exist, check to see if the databases directory existsFile f =NewFile (Db_path); //If the database directory does not exist, create a new directory if(!f.exists ()) {F.mkdir (); } //Get the Assets directory we are ready to use as an input stream for the SQLite databaseInputStream is=context.getassets (). open (db_name); //output StreamOutputStream OS =NewFileOutputStream (Db_path); //File Write byte[] buffer =New byte[1024x768]; intlength; while(length = is. Read (buffer)) >0) {os.write (buffer,0, length); } //Close File StreamOs.flush (); Os.close (); is. Close (); } Catch(Exception e) {e.printstacktrace (); } } returnDb_path;}
Direct read db file for Android database operation