Created
November 2, 2019 17:45
-
-
Save rahulshah456/557664f3046cab6e9a67d32d5308b060 to your computer and use it in GitHub Desktop.
Read Json data from android assets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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