Android Packaging installation to join the external database, I have this requirement so I wrote the following code, now share to everyone
Copy Code code as follows:
public void CreateDatabase () {
Try
{
Get the absolute path to the. db file
String databasefilename = Database_path + database_filename;
File dir = new file (rootdirectory);
If the directory does not exist, create this directory
if (!dir.exists ())
Dir.mkdir ();
If the/data/data/org.itec.android.classroom
The. db file does not exist in the directory, then copy the file from the Res\raw directory to the directory
if (!) ( New File (DatabaseFileName)). Exists ()) {
Get the InputStream object that encapsulates the. db file
InputStream is = Getresources (). Openrawresource (R.raw.mydb);
FileOutputStream fos = new FileOutputStream (databasefilename);
byte[] buffer = new byte[7168];
int count = 0;
Start copying. db files
while ((count = is.read (buffer)) > 0) {
Fos.write (buffer, 0, count);
}
Fos.close ();
Is.close ();
}
}
catch (Exception e) {
}
}