zoukankan      html  css  js  c++  java
  • 将输入流InputStream转换为String

    public static String convertStreamToString(InputStream is) {
    /*
    * To convert the InputStream to String we use the BufferedReader.readLine()
    * method. We iterate until the BufferedReader return null which means
    * there's no more data to read. Each line will appended to a StringBuilder
    * and returned as String.
    */
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();

    String line = null;
    try {
    while ((line = reader.readLine()) != null) {
    sb.append(line + " ");
    }
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    try {
    is.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    return sb.toString();
    }

  • 相关阅读:
    meta属性
    博客
    概念术语
    装饰器与生成器
    Linux基础
    线程
    网络编程之socket
    网络编程之网络基础部分

    内置函数(max,min,zip)及文件处理
  • 原文地址:https://www.cnblogs.com/abc199812/p/6860160.html
Copyright © 2011-2022 走看看