Skip to content

Instantly share code, notes, and snippets.

@skyfishjy
Last active April 15, 2016 21:22
Show Gist options
  • Save skyfishjy/9bb7ed533d85b88dc9ec to your computer and use it in GitHub Desktop.
Save skyfishjy/9bb7ed533d85b88dc9ec to your computer and use it in GitHub Desktop.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
* Created by skyfishjy on 5/5/15.
*/
public class IOUtils {
/**
* Reads an input stream line by line and converts it into String.
* @param inputStream the inputStream need to convert
*/
public static String convertStreamToString(InputStream inputStream) {
BufferedReader bufferedReader;
StringBuilder stringBuilder = new StringBuilder();
try {
String line;
bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF8"));
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line);
}
bufferedReader.close();
} catch (IOException ignored) {
}
return stringBuilder.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment