java--InputStram转化String类型

 private static String getStringFromInputStream(InputStream is)
      throws IOException {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];
    int len = -1;
    while ((len = is.read(buffer)) != -1) {
      os.write(buffer, 0, len);
    }
    is.close();
    String state = os.toString();// 把流中的数据转换成字符串,采用的编码是utf-8(模拟器默认编码)
    os.close();
    return state;
  }

猜你喜欢

转载自blog.csdn.net/qq_21937107/article/details/88817726