InputSream转为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 + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
InputSream转为String的更多相关文章
- java语言中Object转为String的几种形式
在java项目的实际开发和应用中,常常需要用到将对象转为String这一基本功能.本文将对常用的转换方法进行一个总结.常用的方法有Object.toString(),(String)要转换的对象,St ...
- [C#]List<int>转string[],string[]转为string
// List<int>转string[] public string[] ListInt2StringArray(List<int> input) { return Arra ...
- inputStream输入流转为String对象(将String对象转为inputStream输入流)
不得不说org.apache.commons包下有很多实用的工具类. org.apache.commons.io.IOUtils; 要将inputStream输入流转为String对象,只需使用org ...
- netty: 将传递数据格式转为String,并使用分隔符发送多条数据
自定义分割符,用:DelimiterBasedFrameDecoder类 ByteBuf转String,用StringDecoder类 参考代码: //设置连接符/分隔符,换行显示 ByteBuf b ...
- 集合流之“将List<Integer>转为String并用逗号分割”
1.使用[流+Collectors]转换 import java.util.ArrayList; import java.util.List; import java.util.stream.Coll ...
- C++中int转为char 以及int 转为string和string 转int和空格分隔字符串
1.对于int 转为char 直接上代码: 正确做法: void toChar(int b) { char u; ]; _itoa( b, buffer, ); //正确解法一 u = buffer[ ...
- C++中int转为char 以及int 转为string和string 转int和字符串的split
1.对于int 转为char 直接上代码: 正确做法: void toChar(int b) { char u; ]; _itoa( b, buffer, ); //正确解法一 u = buffer[ ...
- Object类型的转为String类型
Map<String, Object> scaleMap = new HashMap(): scaleMap.put("name","张三"); S ...
- 优雅的将Map转为String工具类
import com.alibaba.fastjson.JSONObject;import org.apache.commons.lang3.StringUtils; import java.lang ...
随机推荐
- Git rebase的使用
rebase 在 Git 中整合来自不同分支的修改主要有两种方法:merge 以及 rebase. 在本节中我们将学习什么是“rebase”,怎样使用“rebase”,并将展示该操作的惊艳之处,以及指 ...
- Android灯光系统_编写HAL_lights.c【转】
本文转载自:https://blog.csdn.net/qq_33443989/article/details/77074411 1>. 编写灯光系统的HAL层 之 HAL_light.c1&l ...
- linux内核中侧async_tx是什么?
答: 异步内存传输api(asynchronous memory transfer/transform API),这是一种api,用来为应用提供操作DMA的API. 下图是async_tx在架构中所处 ...
- P2153 [SDOI2009]晨跑
思路 典型的最小费用最大流问题,拆点,每个点对应的入点和出点之间连一条cap=1的边表示只能经过一次的限制条件 然后其他边从u的出点连向v的入点即可 代码 #include <cstdio> ...
- 怎么在父窗口调用它页面的iframe里面数据,进行操作?
注:在服务器下操作有效果,本地无效 document.getElementById("taskdetail1").contentWindow.test(a) document.ge ...
- 非托管C++互操作
.NET简谈互操作(一:开篇介绍) .NET简谈互操作(二:先睹为快) .NET简谈互操作(三:基础知识之DllImport特性) .NET简谈互操作(四:基础知识之Dispose非托管内存) .NE ...
- QLineEdit响应回车时避免Button同时响应
pButton->setAutoDefault(false);
- idea使用教程(1)
引言:本教程主要讲解一下常用的配置安装方法,不包含软件安装,按照以下教程配置后,可以直接用于生产环境. 参考网址:参考了尚硅谷关于idea的使用教学视屏 idea注册码地址:http://idea.l ...
- AjaxHandler
概要 AjaxHandler组件是在ASP.NET MVC Web应用程序中实现ajax功能的一系列扩展方法,该组件的最初的实现方法借鉴了网上流行的部分源代码, ,经过博主不断完善和改进后推出的比较成 ...
- webbench高并发测试
安装ctags sudo apt-get install ctags 安装webbench 下载webbench http://home.tiscali.cz/~cz210552/distfiles/ ...