Android binds SQLite databases and programs for release together

Source: Internet
Author: User

AProgramOne installation requires several pieces of data,
The current program first checks whether the table exists. If the table does not exist, it is created. If the table exists, it is not created. So I went online for half a day and found a solution. Put the database files under Res/raw.
Looks like android
Raw files are not compiled into binary files. Then, the program checks whether the database table does not exist. Then, the raw database file is copied to the mobile phone through the input/output stream.CodeAs follows:

Try {

Log. E (database_path, database_path );
String databasefilename = database_path + "/" + database_filename;
File dir = new file (database_path); cargo expert

If (! Dir. exists ())
Dir. mkdir ();

If (! (New file (databasefilename). exists ()){

Inputstream is = getresources (). openrawresource (
R. Raw. healthmanage );
Fileoutputstream Fos = new fileoutputstream (databasefilename );
Byte [] buffer = new byte [8192];
Int COUNT = 0;

While (COUNT = is. Read (buffer)> 0) {Women's brand ranking
FOS. Write (buffer, 0, count );
}

FOS. close ();
is. close ();
}< br>
} catch (exception e) {
log. E ("error", "error");
}

Related Article

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.