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 + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
} return sb.toString();
}

InputSream转为String的更多相关文章

  1. java语言中Object转为String的几种形式

    在java项目的实际开发和应用中,常常需要用到将对象转为String这一基本功能.本文将对常用的转换方法进行一个总结.常用的方法有Object.toString(),(String)要转换的对象,St ...

  2. [C#]List<int>转string[],string[]转为string

    // List<int>转string[] public string[] ListInt2StringArray(List<int> input) { return Arra ...

  3. inputStream输入流转为String对象(将String对象转为inputStream输入流)

    不得不说org.apache.commons包下有很多实用的工具类. org.apache.commons.io.IOUtils; 要将inputStream输入流转为String对象,只需使用org ...

  4. netty: 将传递数据格式转为String,并使用分隔符发送多条数据

    自定义分割符,用:DelimiterBasedFrameDecoder类 ByteBuf转String,用StringDecoder类 参考代码: //设置连接符/分隔符,换行显示 ByteBuf b ...

  5. 集合流之“将List<Integer>转为String并用逗号分割”

    1.使用[流+Collectors]转换 import java.util.ArrayList; import java.util.List; import java.util.stream.Coll ...

  6. C++中int转为char 以及int 转为string和string 转int和空格分隔字符串

    1.对于int 转为char 直接上代码: 正确做法: void toChar(int b) { char u; ]; _itoa( b, buffer, ); //正确解法一 u = buffer[ ...

  7. C++中int转为char 以及int 转为string和string 转int和字符串的split

    1.对于int 转为char 直接上代码: 正确做法: void toChar(int b) { char u; ]; _itoa( b, buffer, ); //正确解法一 u = buffer[ ...

  8. Object类型的转为String类型

    Map<String, Object> scaleMap = new HashMap(): scaleMap.put("name","张三"); S ...

  9. 优雅的将Map转为String工具类

    import com.alibaba.fastjson.JSONObject;import org.apache.commons.lang3.StringUtils; import java.lang ...

随机推荐

  1. python 函数,闭包

    假如有一个函数,实现返回两个数中的较大值: def my_max(x,y): m = x if x>y else y return mbigger = my_max(10,20)print(bi ...

  2. Delphi XE5 for Android (十一)

    以下内容是根据Delphi的帮助文件进行试验的,主要测试Android下的消息提醒. 首先建立一个空白的Android工程,然后在窗体中加入一个TNotificationCenter控件,如下图: 再 ...

  3. Bootstrap3基础 img-thumbnail 给图片加一个圆角的边框

      内容 参数   OS   Windows 10 x64   browser   Firefox 65.0.2   framework     Bootstrap 3.3.7   editor    ...

  4. 赞 ( 84 ) 微信好友 新浪微博 QQ空间 180 SSD故事会(14):怕TLC因为你不了解!【转】

    本文转载自:https://diy.pconline.com.cn/750/7501340.html [PConline 杂谈]从前,大家谈TLC色变:如今,TLC攻占SSD半壁江山.是的,这个世界就 ...

  5. linux内核中的crng是什么?

    答: 一致性随机数生成器(congruential random number generator)

  6. 【做题】apc001_f-XOR Tree——巧妙转化及dp

    对树上的路径进行操作是十分难处理的事情.一开始的思路主要针对于\(a_i<=15\)这一特殊性质上.于是考虑了\(a_i<=1\)的情况,然而除了糊出一个适用范围极小的结论外,并没有什么用 ...

  7. 如何查看sonarqube的版本

    Server Logs & System Info The System Info page is found at Administration > System. It gives ...

  8. asp.net core mvc 中在C# 代码中写 js 或html 文本

    https://blog.csdn.net/orichisonic/article/details/62046621 使用<text>这个伪元素来强制Razor从编译模式返回到内容模式: ...

  9. log4j2日志xml配置——不同级别的日志分别记录在不同的文件

    <?xml version="1.0" encoding="UTF-8"?> <!--日志级别以及优先级排序: OFF > FATAL ...

  10. 深度学习课程笔记(十二) Matrix Capsule

    深度学习课程笔记(十二) Matrix Capsule with EM Routing  2018-02-02  21:21:09  Paper: https://openreview.net/pdf ...