InputStream与String 转换
来源:互联网 发布:unity3d transform 编辑:程序博客网 时间:2024/04/30 05:43
转自:http://wesker0918.iteye.com/blog/286642和http://www.oschina.net/code/snippet_54371_3138两处
String --> InputStream
- InputStream StringToInputStream(String str){
- ByteArrayInputStream stream = new ByteArrayInputStream(str.getBytes());
- return stream;
- }
InputStream --> String
- String inputStreamToString(InputStream is){
- BufferedReader in = new BufferedReader(new InputStreamReader(is));
- StringBuffer buffer = new StringBuffer();
- String line = "";
- while ((line = in.readLine()) != null){
- buffer.append(line);
- }
- return buffer.toString();
- }
int i = -1;//org.apache.commons.io.output.ByteArrayOutputStreamByteArrayOutputStream baos = new ByteArrayOutputStream();while ((i = is.read()) != -1) {baos.write(i);}String content = baos.toString();int i = -1;byte[] b = new byte[1024];StringBuffer sb = new StringBuffer();while ((i = is.read(b)) != -1) {sb.append(new String(b, 0, i));}String content = sb.toString();
- InputStream与String 转换
- String与InputStream转换
- InputStream 与 String转换
- String与InputStream相互转换
- String与InputStream相互转换
- String与InputStream相互转换
- String与InputStream相互转换
- String与InputStream相互转换
- String与InputStream相互转换
- String与InputStream相互转换
- String与InputStream相互转换
- String与InputStream相互转换
- InputStream与String相互转换
- String与InputStream相互转换
- String与InputStream相互转换
- String与InputStream相互转换
- String与InputStream相互转换
- String与InputStream相互转换
- E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
- 织梦DedeCMS正式发布5.7版 老牌CMS再发力
- 一个程序员的十年程序人生感悟
- 使用 jsoup 对 HTML 文档进行解析和操作
- asp.net webservice常见问题收集
- InputStream与String 转换
- android 数据存储
- Interview Questions for ASP.NET Part - 1
- java -8
- Windows系统 的错误代码信息解释
- Android面试题
- flex datagrid组件 中添加别的组件(上半部分)
- 实现自己的printf函数
- Rman备份与恢复