Created
October 26, 2012 22:30
-
-
Save kristopherjohnson/3961936 to your computer and use it in GitHub Desktop.
Read string from InputStream
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
// http://stackoverflow.com/a/9949592/1175 | |
String readStringFromStream(InputStream in) throws IOException { | |
StringBuilder out = new StringBuilder(); | |
BufferedReader br = new BufferedReader(new InputStreamReader(in)); | |
for(String line = br.readLine(); line != null; line = br.readLine()) | |
out.append(line); | |
br.close(); | |
return out.toString(); | |
} | |
String readStringFromStream(InputStream in, String charsetName) throws IOException { | |
StringBuilder out = new StringBuilder(); | |
BufferedReader br = new BufferedReader(new InputStreamReader(in, charsetName)); | |
for(String line = br.readLine(); line != null; line = br.readLine()) | |
out.append(line); | |
br.close(); | |
return out.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment