我想存储JSONObject
在一个文件中。为此,我将对象转换为字符串,然后将其存储在文件中。我使用的代码是:
String card_string = card_object.toString();
//card_object is the JSONObject that I want to store.
f = new File("/sdcard/myfolder/card3.Xcard");
//file 'f' is the file to which I want to store it.
FileWriter fw = new FileWriter(f);
fw.write(card_string);
fw.close();
代码按我的意愿工作。现在我想从文件中检索该对象。我该怎么做?我对使用什么来读取文件感到困惑?一个InputStream
或一个FileReader
或BufferedReader
或什么。我是 JAVA / android 开发的新手。
请帮忙。欢迎使用简单的语言详细解释在不同场景(如此类)中使用哪些 I/O 功能。我查看了文档,但欢迎您提出建议。