我在尝试缓存和读取 json 文件时遇到问题,我使用 google dev 的示例缓存文件,然后尝试使用不同的函数读取文件readCache(),但出现错误
outputStream.read() -> 无法解析方法 read().....
有人可以解释一下我在做什么错吗?
private void cacheFile(JSONObject response) {
JSONObject res = response;
String filename = "jsonfile";
FileOutputStream outputStream;
try {
outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
outputStream.write(res.toString().getBytes("utf-8"));
outputStream.close();
Log.e(TAG, "Success");
} catch (Exception e) {
e.printStackTrace();
}
}
private void readCache(String filename) {
FileOutputStream outputStream;
try {
outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
outputStream.read();
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
森栏
相关分类