サーバーから取得したデータをファイルに保存しようとしていますが、うまくいきません。
誰かが私を助けることができますか?はい、私は Java を学び始めたばかりの初心者です。
これが私のJSONコードです...
JSONObject json = new JSONObject(str);
JSONArray data = json.getJSONArray("data");
for (int i = 0; i < data.length(); i++) {
JSONObject object = data.getJSONObject(i);
JSONObject category = object.getJSONObject("Category");
Category_ID.add(Long.parseLong(category.getString("Category_ID")));
Category_name.add(category.getString("Category_name"));
Category_image.add(category.getString("Category_image"));
Log.d("Category name", Category_name.get(i));
}
そして、ここにファイルを保存しようとしているコードがあります...
String FILENAME = "somefile";
String string = "hello world!";
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();
FileInputStream fis = openFileInput(FILENAME);
fis.read(string);
fis.close();