Created
January 27, 2016 04:45
-
-
Save arielmagbanua/e9b5b9317fcf12d5c8ca to your computer and use it in GitHub Desktop.
Reading local json from asset folder in android
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
public String loadJSONFromAsset() { | |
String json = null; | |
try { | |
InputStream is = getAssets().open("file_name.json"); | |
int size = is.available(); | |
byte[] buffer = new byte[size]; | |
is.read(buffer); | |
is.close(); | |
json = new String(buffer, "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