【发布时间】:2016-01-20 21:38:06
【问题描述】:
我尝试加载两个文件时出错。 我的问题是如何将两个 json 文件加载到领域中。
以下是加载json文件:
private void loadJsonFromStream() throws IOException {
InputStream stream = getAssets().open("school.json");
realm.beginTransaction();
try {
realm.createAllFromJson(School.class, stream);
realm.commitTransaction();
} catch (IOException e) {
// Remember to cancel the transaction if anything goes wrong.
realm.cancelTransaction();
} finally {
if (stream != null) {
stream.close();
}
}
}
下面正在加载设置设置文件。
private void loadJsonSettingFromStream() throws IOException {
InputStream streamSetting = getAssets().open("setting.json");
realm.beginTransaction();
try {
realm.createAllFromJson(Setting.class, streamSetting);
realm.commitTransaction();
} catch (IOException e) {
// Remember to cancel the transaction if anything goes wrong.
realm.cancelTransaction();
} finally {
if (streamSetting != null) {
streamSetting.close();
}
}
【问题讨论】:
-
显示您的错误可能会让其他人为您提供更好的帮助。