How to read LARGE Sqlite file to be copied into Android emulator, or device from assets folder?

Posted by Peter SHINe ??? on Stack Overflow See other posts from Stack Overflow or by Peter SHINe ???
Published on 2010-05-28T10:28:50Z Indexed on 2010/05/28 10:31 UTC
Read the original article Hit count: 368

Filed under:
|
|
|
|

I guess many people already read this article:

Using your own SQLite database in Android applications: http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/comment-page-2/#comment-12368

However it's keep bringing IOException at

while ((length = myInput.read(buffer))>0){
    myOutput.write(buffer, 0, length);
}

I’am trying to use a large DB file. It’s as big as >8MB I built it using sqlite3 in Mac OS X, inserted UTF-8 encoded strings (for I am using Korean), added android_meta table with ko_KR as locale, as instructed above.

However, When I debug, it keeps showing IOException at

length=myInput.read(buffer)

I suspect it’s caused by trying to read a big file. If not, I have no clue why. I tested the same code using much smaller text file, and it worked fine.

Can anyone help me out on this? I’ve searched many places, but no place gave me the clear answer, or good solution. Good meaning efficient or easy.

I will try use BufferedInput(Output)Stream, but if the simpler one cannot work, I don’t think this will work either.

Can anyone explain the fundamental limits in file input/output in Android, and the right way around it, possibly? I will really appreciate anyone’s considerate answer. Thank you.

WITH MORE DETAIL:

private void copyDataBase() throws IOException{

     //Open your local db as the input stream
     InputStream myInput = myContext.getAssets().open(DB_NAME);

     // Path to the just created empty db
     String outFileName = DB_PATH + DB_NAME;

     //Open the empty db as the output stream
     OutputStream myOutput = new FileOutputStream(outFileName);

     //transfer bytes from the inputfile to the outputfile
     byte[] buffer = new byte[1024];
     int length;
     while ((length = myInput.read(buffer))>0){
      myOutput.write(buffer, 0, length);
     }

     //Close the streams
     myOutput.flush();
     myOutput.close();
     myInput.close();

    }

© Stack Overflow or respective owner

Related posts about android

Related posts about file