【发布时间】:2013-06-15 05:31:19
【问题描述】:
我想加载一个模型文件,该文件将出现在用户的外部存储中。模型文件的大小可以达到 20MB 左右。它包含由 '\n' 分隔的 x,y,z 信息。当我尝试通过我的方法加载一个小文件时,它运行良好。但是对于大文件,应用程序要求强制退出。
File dir = Environment.getExternalStorageDirectory();
File file = new File(dir,"model_Cube.txt");
BufferedReader reader = null;
List<Float> list = new ArrayList<Float>();
try {
reader = new BufferedReader(new FileReader(file));
String text = null;
while ((text = reader.readLine()) != null) {
list.add(Float.parseFloat(text));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
try {
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
triangleCoords = new float[list.size()];
for (int i = 0; i < list.size(); i++) {
Float f = list.get(i);
triangleCoords[i] = (float) (f.floatValue()/10.0); // Or whatever default you want.
}
【问题讨论】:
-
...那么为什么文件需要那么大才能执行您正在执行的操作?将其存储在 SQLite 中不是更好(如果数据太密集)吗?
-
嗯,它包含一个 3D 模型的点云信息,比如泰姬陵。现在我想做的是阅读点云信息并查看它。为了创建数据库,我仍然需要先读取文件,不是吗?
-
@Makoto 我认为 Android 中的 SQLite BLOB 限制为 1MB。
-
我在这里使用扫描仪stackoverflow.com/a/54961878/7680587提供了解决方案@