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/" + 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 ");
}
}
From weizhiai12's column