Skip to content

Instantly share code, notes, and snippets.

@pantos27
Created November 29, 2016 10:32
Show Gist options
  • Save pantos27/69319c349af9a064e174143954858062 to your computer and use it in GitHub Desktop.
Save pantos27/69319c349af9a064e174143954858062 to your computer and use it in GitHub Desktop.
Read\convert an InputStream to a String Java\Android
static void openStream(final Context context){
final InputStream stream = context.getResources().openRawResource(R.raw.messages);
String string=convertStreamToString(stream);
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
static String convertStreamToString(java.io.InputStream is) {
java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment