Inputstream to String

From Null-pointer

Jump to: navigation, search

This is the fastest way for reading an inputstream and converting it to a string I've found

private static String getStringFromInputStream(InputStream is) throws Exception {
  StringWriter writer = new StringWriter();
  InputStreamReader reader = new InputStreamReader(is);
 
  char[] buffer = new char[1024*4];
  int data = 0;
  while (-1 != (data = reader.read(buffer))){
    writer.write(buffer,0,data);
  }
  return writer.toString();
}

See Also


References

Personal tools