In the Android system, if you need to use a database, we generally use the sqllite database and store the database in the res \ raw directory. This facilitates the release of the database together when the system is released.
When accessing the database in the system, we generally copy the database to the directory of the name of our current package under data/data, which makes it easier for us to perform operations.
You can refer to the following sample code:
// Copy and load data in the regional database
Private void copyandloaddb (){
// When you run the application for the first time, load the database to data/Name of the current package/database/<db_name>
Dir = new file ("Data/data/" + getpackagename () + "/databases ");
If (! Dir. exists () |! Dir. isdirectory ()){
Dir. mkdir ();
}
File = new file (Dir, "china_province_city_zone.db3 ");
If (! File. exists ()){
Fileutil. loaddbfile (R. Raw. china_province_city_zone, file,
Getresources (), getpackagename ());
Log. D ("winestock", "database load successfully ");
}
}