Last active
August 29, 2015 14:06
-
-
Save defHLT/3ac50c765f3cf289da03 to your computer and use it in GitHub Desktop.
read Android raw resource file to Java string
This file contains 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 getRawResource(int resource) { | |
String res = null; | |
InputStream is = getContext().getResources().openRawResource(resource); | |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
byte[] b = new byte[1]; | |
try { | |
while ( is.read(b) != -1 ) { | |
baos.write(b); | |
}; | |
res = baos.toString(); | |
is.close(); | |
baos.close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment