我想很多人都已经看过这篇文章:如何阅读LARGE Sqlite文件复制到Android模拟器或资产文件夹中的设备?
但是它再拿IOException异常在
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
我'试图用一个大的数据库文件。 它大到> 8MB 我在Mac OS X中使用sqlite3构建了它,插入了UTF-8编码的字符串(对于我使用的是韩语), 将ko_KR作为语言环境添加了android_meta表,如上所述。
然而,当我调试,它不断出现在
length=myInput.read(buffer)
IOException异常,我怀疑它是由试图读取大文件引起的。如果没有,我不知道为什么。 我使用更小的文本文件测试了相同的代码,并且它工作正常。
谁能帮我这个?我搜遍了很多地方,但没有一个地方给我明确的答案,或者很好的解决方案。 有效或容易的好意思。
我会尝试使用BufferedInput(输出)流,但如果更简单的不能工作,我不认为这也可以。
谁能解释在文件输入/输出的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();
}
为什么需要本地如此多的数据?看起来像移动应用程序开发的一个基本问题......一些Android设备仍然有限的内存,重新设计你的应用程序,以便它从网上读取并在本地缓存少量数据,8MB对于只有一个应用程序看起来很多(考虑复杂的应用程序,如谷歌地图,只需8MB ...) – 2010-05-28 19:24:31