Skip to content

Instantly share code, notes, and snippets.

@rahulshah456
Created November 2, 2019 17:45
Show Gist options
  • Select an option

  • Save rahulshah456/557664f3046cab6e9a67d32d5308b060 to your computer and use it in GitHub Desktop.

Select an option

Save rahulshah456/557664f3046cab6e9a67d32d5308b060 to your computer and use it in GitHub Desktop.
Read Json data from android assets
private String loadJSONFromAsset() {
String json;
try {
InputStream is = mContext.getAssets().open("banners.json");
int size = is.available();
byte[] buffer = new byte[size];
int status = is.read(buffer);
Log.d(TAG, "loadJSONFromAsset: status = " + status);
is.close();
json = new String(buffer, StandardCharsets.UTF_8);
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
return json;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment