Read InputStream KB by KB - Android java.io

Android examples for java.io:InputStream

Description

Read InputStream KB by KB

Demo Code

import java.io.InputStream;

public class Main {

  public static String getContentByString(InputStream is) {
    try {/* w  w  w  .j  av a 2  s.  c o  m*/
      if (is == null)
        return null;
      byte[] b = new byte[1024];
      int len = -1;
      StringBuilder sb = new StringBuilder();
      while ((len = is.read(b)) != -1) {
        sb.append(new String(b, 0, len));
      }
      return sb.toString();
    } catch (Exception e) {
      // TODO: handle exception
    }
    return null;
  }

}

Related Tutorials