Skip to content

Instantly share code, notes, and snippets.

@defHLT
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save defHLT/3ac50c765f3cf289da03 to your computer and use it in GitHub Desktop.
Save defHLT/3ac50c765f3cf289da03 to your computer and use it in GitHub Desktop.
read Android raw resource file to Java string
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