我想很多人已经读过这篇文章:
在 Android 应用程序中使用您自己的 SQLite 数据库:http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/comment-page-2/#comment-12368 http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/comment-page-2/#comment-12368
然而它一直在带来 IOException
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
我正在尝试使用一个大的数据库文件。大小>8MB我在 Mac OS X 中使用 sqlite3 构建它,插入 UTF-8 编码字符串(因为我使用韩语),
添加了 android_meta 表,其中 ko_KR 作为区域设置,如上所述。
但是,当我调试时,它一直显示 IOException
length=myInput.read(buffer)
我怀疑这是由于尝试读取大文件引起的。如果没有,我不知道为什么。
我使用更小的文本文件测试了相同的代码,并且运行良好。
谁能帮我解决这个问题吗?我找了很多地方,但没有一个地方给我明确的答案,或者好的解决方案。
好的意思是高效或简单。
我会尝试使用缓冲输入(输出)流,但如果更简单的方法不起作用,我认为这也不起作用。
谁能解释一下 Android 中文件输入/输出的基本限制,以及可能的正确解决方法?我真的很感激任何人的体贴回答。谢谢。
更多细节:
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();
}