Android reads the database information that already exists in the APK

Source: Internet
Author: User

In the Android database programming, have you ever encountered, I want to from the specified location of the existing database to operate the problem. Before I tried a lot of methods did not succeed, and then found a solution to the method.
The following describes the meaning of this code, the first step to determine whether the specified path strength exists, does not exist on the creation of design material Daquan. The second step is to copy the database under Android resources to the specified path below. The third step is to open or create the database according to the specified path, and then get the object of manipulating the database, get the object of manipulating the database, and then we can make the table in the database increase and remove the operation.

1. [Code]android program reads a database that already exists in the project     string databasefilename = Database_path + "/" + database_name;  &NB Sp File dir = new file (database_path);    if (!dir.exists ())      dir.mkdir ();    if (! ( New File (DatabaseFileName)). Exists ()) {     inputstream is = Context.getresources (). Openrawresource ( R.raw.jobexam);     fileoutputstream fos = new FileOutputStream (databasefilename);      byte[] buffer = new byte[8192];http://www.huiyi8.com/sheji/     int count = 0;     while (c Ount = is.read (buffer)) > 0) {      fos.write (buffer, 0, count);     }    &NBSP ; Fos.close ();     is.close ();   }    db = Sqlitedatabase.openorcreatedatabase ( DatabaseFileName, NULL);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.