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 ...
随机推荐
- MFC中状态栏显示鼠标坐标位置
原文:MFC中状态栏显示鼠标坐标位置,蝈蝈 1,利用MFC向导创建一个应用工程ewq. 2,打开ResourceView,右击Menu菜单,插入Menu,在空白处双击,Caption中填入Point. ...
- delphi 中使用WaitForMultipleObjects等待线程执行,再执行后续代码
unit1 [delphi] view plain copyunit Unit1; interface uses Windows, Messages, SysUtils, Variants, Clas ...
- (原创)win7自带IIS7.5+php7.0.10安装教程(图)
php在上周8月18日发布了PHP 7.0 (7.0.10)版本.详细下载页面http://windows.php.net/download/,根据自身电脑配置情况酌情下载版本.win7旗舰版,iis ...
- C语言基础--宏
宏在C语言中经常使用,在linux的源码中可以看到很多宏的高级应用.因此不理解宏,就很难理解代码.本文参考一些互联网资料做一些总结,希望给大家带来帮助. 先说说使用宏的优点及缺点: 优点: 1.提高代 ...
- bzoj 3123 [Sdoi2013]森林(主席树,lca,启发式合并)
Description Input 第一行包含一个正整数testcase,表示当前测试数据的测试点编号.保证1≤testcase≤20. 第二行包含三个整数N,M,T,分别表示节点数.初始边数.操作数 ...
- C++11 并发指南------std::thread 详解
参考: https://github.com/forhappy/Cplusplus-Concurrency-In-Practice/blob/master/zh/chapter3-Thread/Int ...
- 二叉搜索树算法详解与Java实现
二叉查找树可以递归地定义如下,二叉查找树或者是空二叉树,或者是满足下列性质的二叉树: (1)若它的左子树不为空,则其左子树上任意结点的关键字的值都小于根结点关键字的值. (2)若它的右子树不为空,则其 ...
- Spark生态之Spark BlinkDB
- AlertDialog
1.AlertDialog点击时不自动消失 //在setPositiveButton和setNegativeButton根据自己的逻辑处理,大概代码如下 if(validate){//验证通过自动消失 ...
- Java持久化存储对象Properties的方法list、store、load
package FileDemo; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStrea ...