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 的转换的更多相关文章

  1. InputStream,String和Reader之间的转换

    1.String –> InputStreamInputStrem is = new ByteArrayInputStream(str.getBytes());orByteArrayInputS ...

  2. java常用string inputStream转换

    1.String –> InputStream InputStrem is = new ByteArrayInputStream(str.getBytes()); 或者 ByteArrayInp ...

  3. java基础之和String相关的一些转换

      String虽然不是java的基本数据类型,但使用的频率却非常之高,可以说是很常见了. 列举几个常见的关于String的转换,写的有点过于简洁,欢迎纠错和补充   1.Object和String的 ...

  4. 013-java中的IO操作-InputStream/Reader、OutputStream/Writer

    一.概述 IO流用来处理设备之间的数据传输,上传文件和下载文件,Java对数据的操作是通过流的方式,Java用于操作流的对象都在IO包中. 流是一组有顺序的,有起点和终点的字节集合,是对数据传输的总称 ...

  5. Android Bitmap与DrawAble与byte[]与InputStream之间的转换工具类【转】

    package com.soai.imdemo; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; ...

  6. String inputStream file转化

    String --> InputStreamByteArrayInputStream stream = new ByteArrayInputStream(str.getBytes()); Inp ...

  7. go中string和slice no-copy转换

    在go里面,string和slice的互换是需要进行内存拷贝的,虽然在底层,它们都只是用 pointer + len来表示的一段内存. 通常,我们不会在意string和slice的转换带来的内存拷贝性 ...

  8. string 到 wstring的转换

    string 到 wstring的转换_一景_新浪博客     string 到 wstring的转换    (2009-08-10 20:52:34)    转载▼    标签:    杂谈    ...

  9. 利用Gson进行String和对象的转换

    利用Gson进行String和对象的转换 /** * 从JsonStr中解析BUserBase * @param jsonStr * @return */ public static BUserBas ...

随机推荐

  1. POJ 1655-Balancing Act(树形dp)

    题意: 求n个节点的树中哪个节点删除以后得到的最大连通分量最小. 分析:同上题 #include <map> #include <set> #include <list& ...

  2. MAC下显示或者隐藏文件的命令

    显示Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool true 隐藏Mac隐藏文件的命令:defaults writ ...

  3. <转>堆和栈的区别

    http://blog.csdn.net/hairetz/article/details/4141043 一.预备知识—程序的内存分配    一个由C/C++编译的程序占用的内存分为以下几个部分    ...

  4. 打印出从1到最大的n位十进制数

    首先这一题会溢出,要考虑的大数问题.所以不能用简单的是int类型数来表示(32位无符号int 范围是0x00000000···0xFFFFFFFF),下面主要是非递归的实现代码,自己做了注释方便以后回 ...

  5. mapreduce学习指导及疑难解惑汇总

    原文链接http://www.aboutyun.com/thread-7091-1-1.html 1.思想起源: 我们在学习mapreduce,首先我们从思想上来认识.其实任何的奇思妙想,抽象的,好的 ...

  6. HW6.9

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  7. Guide to make CentOS 7 the perfect desktop

    原文地址:  http://www.dedoimedo.com/computers/fedora-pimp.html My original review of CentOS 7 was less e ...

  8. [Spice-devel] usbredir for Windows Client

    Hello, I have been scouring the internet for information on how to do this. I've successfully instal ...

  9. TCP/IP协议详解内容总结

    TCP/IP协议 TCP/IP不是一个协议,而是一个协议族的统称.里面包括IP协议.IMCP协议.TCP协议. TCP/IP分层:   这里有几个需要注意的知识点: 互联网地址:也就是IP地址,一般为 ...

  10. Java中4大基本加密算法解析

    简单的java加密算法有: BASE64 严格地说,属于编码格式,而非加密算法 MD5(Message Digest algorithm 5,信息摘要算法) SHA(Secure Hash Algor ...