Database replication issues in Android projects

Source: Internet
Author: User

============ Problem Description ============

Java IO stream copied sqlite3 database file, Chinese data query not come out, you have encountered this problem, help me answer

============ Solution 1============

Private void dbimport ()     {        try         {             file dir = new file (Database_path);             //  if the/sdcard/testdb directory exists, create this directory              if  (!dir.exists ())                  dir.mkdir ();             //  if not present in the/sdcard/testdb directory              // test.db file, copy this file from the Asset\db directory to            Catalogue of   // SD Cards (/SDCARD/TESTDB)              if  (!) ( New&nbSp File (DatabaseFilename2)). Exists ())             {//                 file f  =  (New file (databaseFilename2));//                 f.delete ();                 //  get InputStream objects that encapsulate testdatabase.db files                  AssetManager asset =  Getassets ();                 Inputstream is = ("db/database.db");                 FileOutputStream fos = new  FileOutputStream (databaseFilename2);                  byte[] buffer  = new byte[1024];                 int count = 0;                 //  start copying testdatabase.db files                  while  ((count = (buffer))  > 0)                  {                     fos.write (Buffer, 0, count);                 }                  Fos.close ();                 Is.close ();                 //  asset.close ();            }         }        catch  (Exception  e)         {             e.printstacktrace ();        }         // deletedatabase ("testdatabase.db");//delete database     }

This is the import db method that I originally wrote. Also useless to encoding. Japanese database, no problem.

============ Solution 2============


Database replication issues in Android projects

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: 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.