How to read a LARGE Sqlite file for copying to an Android emulator or device from a resource folder?

I think many people have 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 continues to bring an IOException to

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

I am trying to use a large DB file. Its size is> 8 MB. I built it using sqlite3 on Mac OS X, inserted UTF-8 encoded strings (since I use Korean), the android_meta table with ko_KR as the locale is added as above.

However, when I debug, it keeps showing an IOException in

 length=myInput.read(buffer) 

I suspect this is due to an attempt to read a large file. If not, I don’t know why. I tested the same code using a much smaller text file and it worked fine.

Can someone help me with this? I searched for many places, but not one place gave me a clear answer or a good solution. Good value is effective or simple.

I will try to use BufferedInput (Output) Stream , but if it is simpler it cannot work, I do not think this will work either.

Can anyone explain the fundamental limitations of file I / O in Android and maybe the right way? I will greatly appreciate an attentive answer. Thanks.

BIG DETAILS:

 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(); } 
0
source share
4 answers

Can someone help me with this?

Use a smaller file. Or a set of small files that you stitch together into a large file as they are unpacked. Or load the database the first time you run the application.

+2
source

I was there. I believe that the type of RAW resource does not have a maximum size limit (whereas Assets, or, more specifically, the flow associated with an asset, are limited in size).

Once you overcome this obstacle, you should be fine - I had databases on my phone more than 100 MB.

+2
source

Change the file extension to .mp3, for example:

IOException while reading from InputStream

+2
source

I don't know if this will help you, but if other approaches fail, you can try using NIO . For example, here is the implementation of copying the input stream to a file. Alternatively, you can try making a zip file and see if Android can unzip tools that can be unzipped directly to your db folder.

0
source

Source: https://habr.com/ru/post/922816/


All Articles