String 、InputStream、Reader 的转换
1、String –> InputStream
InputStrem is = new ByteArrayInputStream(str.getBytes());
or
ByteArrayInputStream stream
= new ByteArrayInputStream(str.getBytes());
2、InputStream–>String
inputStream input;
StringBuffer out = new StringBuffer();
byte[] b = new byte[4096];
for (int n; (n = input.read(b)) != -1;) {
out.append(new String(b, 0, n));
}
out.toString();
3、Reader –>String
BufferedReader in = new BufferedReader(new InputStreamReader(is));
StringBuffer buffer = new StringBuffer();
String line = " ";
while ((line = in.readLine()) != null){
buffer.append(line);
}
return buffer.toString();
4、String–>Reader
Reader reader = null;
BufferedReader r = new BufferedReader(reader);
StringBuilder b = new StringBuilder();
String line;
while((line=r.readLine())!=null) {
b.append(line);
b.append(“\r\n”);
}
b.toString();
String 、InputStream、Reader 的转换的更多相关文章
- InputStream,String和Reader之间的转换
1.String –> InputStreamInputStrem is = new ByteArrayInputStream(str.getBytes());orByteArrayInputS ...
- java常用string inputStream转换
1.String –> InputStream InputStrem is = new ByteArrayInputStream(str.getBytes()); 或者 ByteArrayInp ...
- java基础之和String相关的一些转换
String虽然不是java的基本数据类型,但使用的频率却非常之高,可以说是很常见了. 列举几个常见的关于String的转换,写的有点过于简洁,欢迎纠错和补充 1.Object和String的 ...
- 013-java中的IO操作-InputStream/Reader、OutputStream/Writer
一.概述 IO流用来处理设备之间的数据传输,上传文件和下载文件,Java对数据的操作是通过流的方式,Java用于操作流的对象都在IO包中. 流是一组有顺序的,有起点和终点的字节集合,是对数据传输的总称 ...
- Android Bitmap与DrawAble与byte[]与InputStream之间的转换工具类【转】
package com.soai.imdemo; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; ...
- String inputStream file转化
String --> InputStreamByteArrayInputStream stream = new ByteArrayInputStream(str.getBytes()); Inp ...
- go中string和slice no-copy转换
在go里面,string和slice的互换是需要进行内存拷贝的,虽然在底层,它们都只是用 pointer + len来表示的一段内存. 通常,我们不会在意string和slice的转换带来的内存拷贝性 ...
- string 到 wstring的转换
string 到 wstring的转换_一景_新浪博客 string 到 wstring的转换 (2009-08-10 20:52:34) 转载▼ 标签: 杂谈 ...
- 利用Gson进行String和对象的转换
利用Gson进行String和对象的转换 /** * 从JsonStr中解析BUserBase * @param jsonStr * @return */ public static BUserBas ...
随机推荐
- HDU 1043 Eight BFS
题意:就是恢复成1,2,3,4,5,6,7,8,0; 分析:暴力BFS预处理,所有路径,用康拓展开判重,O(1)打印 93ms 还是很快的 #include <iostream> #inc ...
- Jquery 操作xml 文档的方法
需求: 页面上有两个下拉框,显示游戏大区 和游戏服务器,当游戏大区改变时,游戏服务器也跟着改变 界面部分html代码 <tr class="tkSigUser"> &l ...
- 设备扩展(DEVICE_EXTENSION)
原文链接:http://blog.csdn.net/hazy/article/details/481705 WDM中的结构 ---设备扩展 设备扩展(DEVICE_EXTENSION)是与设备对象 ...
- PHP基本语法的小结
一.PHP能做什么? PHP能做什么?我觉得它很强大,只要我能想到的,它都能做,只是我技术能力还不行╮(╯﹏╰)╭.好吧,一张图,基本了解一下吧(ps:PHP的功能不局限于此( ^_^ )) 图像有点 ...
- CUDA学习资料分享(随时更新)
1.Programming_Massively_Parallel_Processors.pdf 2.CUDA_C_Programming_Guide.pdf 3.CUDA范例精解通用GPU编程.pdf ...
- Storm因机器断电等,启动supervisor异常
Storm因机器断电等,启动supervisor错误 因机器断电或其他异常导致的supervisor意外终止,再次启动时报错: 2014-08-13 10:36:03 b.s.event [ERROR ...
- HW7.6
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- yum 安装 PHP,apache,nginx,mysql
如果是Centos OS 64 位,首先更新 rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarc ...
- hdu4777-Rabbit Kingdom
题意:求区间内与其他任何数都互质的数的个数. 题解:求出每个数左右互质的边界.然后对询问排序,通过树状数组求解. 讲道理真的好难啊= = http://blog.csdn.net/dyx404514/ ...
- A Tour of Go Map literals
Map literals are like struct literals, but the keys are required. package main import "fmt" ...