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();

from http://www.cnblogs.com/clarkchen/archive/2011/03/09/1978570.html

InputStream,String和Reader之间的转换的更多相关文章

  1. MFC中char*,string和CString之间的转换

    MFC中char*,string和CString之间的转换 一.    将CString类转换成char*(LPSTR)类型 方法一,使用强制转换.例如:  CString theString( &q ...

  2. String与StringBuffer之间的转换

    来源:http://www.oschina.net/code/snippet_2261089_47352 package demo; /* String与StringBuffer之间的转换 * Str ...

  3. 【Java】【9】String Date Calendar之间的转换

    前言: 1, Calendar 转化 String 2, Calendar 转化 Date 3,Date 转化 String 4,Date 转化 Calendar 5,String 转化 Calend ...

  4. [java]转:String Date Calendar之间的转换

    String Date Calendar之间的转换 String Date Calendar  1.Calendar 转化 String Calendar calendat = Calendar.ge ...

  5. string和数值之间的转换

    string和数值之间的转换 to_string(val) 一组重载函数,返回数值val的string表示val可以是任何算数类型. stoi(s,p,b),stol(s,p,b),stoul(s,p ...

  6. list,string,tuple,dictionary之间的转换

    list,string,tuple,dictionary之间的转换 类型 String List tuple dictionary String - list(str), str.split() tu ...

  7. java 12-2 String和StringBuffer之间的转换

    为什么我们要讲解类之间的转换: A -- B的转换 我们把A转换为B,其实是为了使用B的功能. B -- A的转换 我们可能要的结果是A类型,所以还得转回来. String和StringBuffer的 ...

  8. java基础类型数据与String类包装类之间的转换与理解

    数据类型转换一般分为三种: 在java中整型,实型,字符型视为简单数据类型,这些数据类型由低到高分别为:(byte,short,char--int-long-float-double) 简单数据类型之 ...

  9. java 13-4 Integer和String、int之间的转换,进制转换

    1.int类型和String类型的相互转换 A.int -- String 推荐用: public static String valueOf(int i) 返回 int 参数的字符串表示形式. B. ...

随机推荐

  1. maven-eclipse 中index.html页面乱码

    maven-eclipse 中index.html页面乱码: pox.xml修改: <project> -- <properties> <argLine>-Dfil ...

  2. LSB含义

    LSB(Least Significant Bit)最低有效位,对任何AD来说,量化后输出的数字信号值都是以1LSB的电压值步进的,介于1LSB之间的电压将按照一定的规则进行入位或舍弃,这个过程中造成 ...

  3. QT+qtablewidget自定义表头【合并单元格】

    1.把下列文件放在工程中[已上传到我的文件中] 2.代码 auto *headview = new HHeadViewClass(Qt::Horizontal, ui.tableWidget); he ...

  4. Jwt访问api提示401错误 Authorization has been denied for this request

    教程  http://bitoftech.net/2015/02/16/implement-oauth-json-web-tokens-authentication-in-asp-net-web-ap ...

  5. springboot中websoket的使用

    知识点:springboot项目中,websoket实时推送技术的介绍与使用      一.双向通信 http协议通信只能由客户端发起请求,服务端返回查询结果,如果我们想定时获取服务端的状态变化,相对 ...

  6. CNN中dropout层的理解

    dropout是在训练神经网络模型时,样本数据过少,防止过拟合而采用的trick.那它是怎么做到防止过拟合的呢? 首先,想象我们现在只训练一个特定的网络,当迭代次数增多的时候,可能出现网络对训练集拟合 ...

  7. 修改JS文件都需要重启Idea才能生效解决方法

    最近开始使用Idea,有些地方的确比eclipse方便.但是我发现工程每次修改JS或者是JSP页面后,并没有生效,每次修改都需要重启一次Tomcat这样的确不方便.我想Idea肯定有设置的方法,不可能 ...

  8. Docker:Err http://archive.ubuntu.com trusty InRelease & E: Unable to locate package [name] 问题

    参考: Docker containers can't resolve DNS on Ubuntu 14.04 Desktop Host Unable to locate package错误解决办法 ...

  9. ZOJ 2587 Unique Attack(最小割唯一性判断)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2587 题意:判断最小割是否唯一. 思路: 最小割唯一性的判断是先跑一遍最大 ...

  10. Spring学习笔记1——基础知识

    1.在java开发领域,Spring相对于EJB来说是一种轻量级的,非侵入性的Java开发框架,曾经有两本很畅销的书<Expert one-on-one J2EE Design and Deve ...