如何读取大sqlite的文件复制到Android模拟器,还是从资产的文件夹的设备?是从、模拟器、文件夹、资产

2023-09-05 10:36:16 作者:柠萌ε嘟嘟

我想很多人都已经看过这篇文章:

在Android应用程序中使用自己的SQLite数据库:http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/comment-page-2/#comment-12368

然而,它的再拿IOException异常在

 ,而((长度= myInput.read(缓冲))大于0){
    myOutput.write(缓冲液,0,长度);
}
 

我'试图用一个大的数据库文件。 这是大如> 8MB 我建立它在Mac OS X中使用sqlite3,插入UTF-8 EN codeD字符串(我是用韩文) 加入android_meta表ko_KR的区域,如上面的指示。

不过,当我调试,它不断出现在IOException异常

 长度= myInput.read(缓冲)
 

我怀疑这是造成试图读取大文件。如果没有,我不知道为什么。 我测试了使用更小的文本文件相同的code,它能正常工作。

谁能帮我一下?我搜索很多地方,但没有地方给了我明确的答复,还是不错的解决方案。 好的意思效率和方便。

我会尝试使用 BufferedInput(输出)流,但如果简单的一个人不能正常工作,我不认为这会擦出火花。

谁能解释文件输入/ Android中输出的基本限制,并围绕它的正确的方式,有可能? 我会真的AP preciate任何人的体贴的答案。谢谢你。

更多的细节:

 私人无效copyDataBase()抛出IOException异常{

     //打开本地数据库作为输入流
     InputStream的myInput = myContext.getAssets()开(DB_NAME)。

     //路径刚刚创建的空分贝
     字符串outFileName = DB_PATH + DB_NAME;

     //打开空分贝的输出流
     的OutputStream myOutput =新的FileOutputStream(outFileName);

     //传输的字节从inputfile中的OUTPUTFILE
     byte []的缓冲区=新的字节[1024];
     INT长;
     而((长度= myInput.read(缓冲液))大于0){
      myOutput.write(缓冲液,0,长度);
     }

     //关闭流
     myOutput.flush();
     myOutput.close();
     myInput.close();

    }
 
android 查看sqlite数据库中内容的方法

解决方案   

谁能帮我出去呢?

使用较小的文件。或一组,你连接在一起形成一个大的文件,你的拆包他们更小的文件。或下载数据库应用程序的第一次运行。

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();

    }

解决方案

Can anyone help me out on this?

Use a smaller file. Or a set of smaller files that you stitch together into a large file as you are unpacking them. Or download the database on the first run of your application.