I created a json file locally. I can view that in data>data>com.example.storage>files>filename.json. Using this, I want to fetch all the text values locally & download a
here is code read JSON data from file that file keep in asset folder in project
public JSONObject readDummyResponse() {
InputStream inputStream = null;
try {
inputStream = this.getAssets().open("sample_response.txt");
} catch (IOException e1) {
e1.printStackTrace();
}
JSONObject jsonObject = null;
if (inputStream != null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(
inputStream));
StringBuffer buffer = new StringBuffer();
String statement;
try {
while ((statement = reader.readLine()) != null) {
if (statement.trim().length() > 0) {
buffer.append(statement);
}
}
} catch (IOException e1) { // TODO Auto-generated catch block
e1.printStackTrace();
}
if (buffer.length() > 0) {
try {
jsonObject = new JSONObject(buffer.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
}
return (JSONObject) jsonObject;
}