//1.字符串转inputstream
String str="aaaaa";
InputStream in = new ByteArrayInputStream(str.getBytes()); //2.inputstream转字符串
String result = readFromInputStream(inputStream);//调用处
//将输入流InputStream变为String
public String readFromInputStream(InputStream in) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = -1;
while ((len = in.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}
baos.close();
in.close(); byte[] lens = baos.toByteArray();
String result = new String(lens,"UTF-8");//内容乱码处理 return result; }
//3.String写入OutputStream中
OutputStream out = System.out;
out.write(str.getBytes()); //4.outputStream转string
ByteArrayOutputStream baos = new ByteArrayOutputStream();
//向OutPutStream中写入,如 message.writeTo(baos);
baos.write(str.getBytes());
String str1= baos.toString();

InputStream和OutputStream与String之间的转换的更多相关文章

  1. 如何在Byte[]和String之间进行转换

    源自C#与.NET程序员面试宝典. 如何在Byte[]和String之间进行转换? 比特(b):比特只有0 1,1代表有脉冲,0代表无脉冲.它是计算机物理内存保存的最基本单元. 字节(B):8个比特, ...

  2. c# String ,String[] 和 List<String>之间的转换

    C#对字符串进行处理时,经常需要进行String,String[]和List<String>之间的转换 本文分析一下它们的差异和转换 一. 1. String > String[] ...

  3. 基本数据类型、包装类、String之间的转换

    package 包装类; /** *8种基本数据类型对应一个类,此类即为包装类 * 基本数据类型.包装类.String之间的转换 * 1.基本数据类型转成包装类(装箱): * ->通过构造器 : ...

  4. java字符数组char[]和字符串String之间的转换

    java字符数组char[]和字符串String之间的转换 觉得有用的话,欢迎一起讨论相互学习~Follow Me 使用String.valueOf()将字符数组转换成字符串 void (){ cha ...

  5. java中Integer 和String 之间的转换

    java中Integer 和String 之间的转换 将数组转换成字符串:char[] array = {'a','b','c','d','e'};String str = new String(ar ...

  6. C#中char[]与string之间的转换;byte[]与string之间的转化

    目录 1.char[]与string之间的转换 2.byte[]与string之间的转化 1.char[]与string之间的转换 //string 转换成 Char[] string str=&qu ...

  7. char* 、const char*和string之间的转换

    1. const char* 和string 转换 (1) const char*转换为 string,直接赋值即可.     EX: const char* tmp = "tsinghua ...

  8. C#中char[]与string之间的转换

    string 转换成 Char[] string ss = "abcdefg"; char[] cc = ss.ToCharArray(); Char[] 转换成string st ...

  9. InputStream、OutputStream、String的相互转换(转)

    //1.字符串转inputStream String string; //...... InputStream is = new ByteArrayInputStream(string.getByte ...

随机推荐

  1. mem中需找特定字符

    memstr //find 'substr' from a fixed-length buffer //('full_data' will be treated as binary data buff ...

  2. Recover deleted pictures in iOS 9

    A case about business secret. The suspect is an engineer in Hitec company, and compeitiors pay lots ...

  3. Excel2007给表格设置成只读加密属性 让他人无法修改

    在制作一些报表和公司的表格时,我们常常需要给Excel表格加密或者设置成只读属性来加以防护这些重要表格.给表格加密可以预防他人无法打开表格,只有通过输入正确的密码后才可以正常打开.设置成只读的话,可以 ...

  4. LLVM language 参考手册(译)(3)

    可见性模式(Visibility Styles) 所有全局变量和函数具有以下的可见性模式之一: “default” - Default style 在那些使用ELF object file格式的平台( ...

  5. logcat保存当前应用程序的日志并上传服务器或指定邮箱

    给大家分享一个项目中用到的日志统计并提交服务器的日志工具类.通过过得当前app的PID,采用命令行的方式实用logcat工具过滤日志.代码区: package org.and.util; import ...

  6. [原]POJ1141 Brackets Sequence (dp动态规划,递归)

    本文出自:http://blog.csdn.net/svitter 原题:http://poj.org/problem?id=1141 题意:输出添加括号最少,并且使其匹配的串. 题解: dp [ i ...

  7. Linux 服务器如何设置文件和文件夹的读写权限

    修改文件可读写属性的方法 例如:把index.htm 文件修改为可写可读可执行: chmod 777 index.htm 要修改目录下所有文件属性可写可读可执行: chmod 777 *.* 该命令中 ...

  8. php反射应用实例代码

    php反射应用示例. 代码如下:<?php function custom(){ } class custom{    public function index(){    }  } prin ...

  9. 将raw里面的数据库文件写入到data中

    package com.city.list.db; import java.io.File; import java.io.FileNotFoundException; import java.io. ...

  10. 傅里叶变换 fft_generic halcon

    傅立叶变换(FT, Fourier Transform)的作用是将一个信号由时域变换到频域.其实就是把数据由横坐标时间.纵坐标采样值的波形图格式,转换为横坐标频率.纵坐标振幅(或相位)的频谱格式.变换 ...