String --> InputStream

InputStream String2InputStream(String str){
ByteArrayInputStream stream = new ByteArrayInputStream(str.getBytes());
return stream;
}

InputStream --> String

String inputStream2String(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();
}

InputStream,String相互转化的更多相关文章

  1. Android Drawable 和String 相互转化

    在我们经常应用开发中,经常用到将drawable和string相互转化.注意这情况最好用于小图片入icon等. public synchronized Drawable byteToDrawable( ...

  2. CString 与 std::string 相互转化

    MFC中CString 与 std::string 相互转化 CString实际是CStringT, 也就是模板类, 在UNICODE环境下,实际是CStringW, 在多字符集环境下,实际是CStr ...

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

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

  4. java中InputStream String

    Java 中获取输入流时,有时候须要将输入流转成String,以便获取当中的内容 ,以下总结一下 InputStream 转成String 的方式  方法1: public String conver ...

  5. 17.Letter Combinations of a Phone Number (char* 和 string 相互转化)

    leetcode 第17题 分析 char*和string相互转化 char*(或者char)转string 可以看看string的构造函数 default (1) string(); copy (2 ...

  6. StrPCopy与StrPas功能正好相反,作用是与C语言字符串和Delphi的String相互转化

    StrPCopy = Copies an AnsiString (long string) to a null-terminated string.function StrPCopy(Dest: PA ...

  7. JavaScript:int string 相互转化

    A.把int型转换成string型 (1) var   x=100    a   =   x.toString()      (2) var   x=100;    a   =   x   +&quo ...

  8. C#中byte[] 与string相互转化问题

    using System; using System.IO; using System.Security.Cryptography; namespace ShareX.UploadersLib.Oth ...

  9. Java InputStream、String、File相互转化

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

随机推荐

  1. JavaScript学习笔记——BOM_window对象

    javascript浏览器对象模型-windwo对象 BOM Browser Object Model window对象 是BOM中所有对象的核心. 一.属性 1.(位置类型-获得浏览器的位置) IE ...

  2. php Hash Table(四) Hash Table添加和更新元素

    HashTable添加和更新的函数: 有4个主要的函数用于插入和更新HashTable的数据: int zend_hash_add(HashTable *ht, char *arKey, uint n ...

  3. How to debug windows service

    Step 1. Add the following code in what you want to debug. System.Diagnostics.Debugger.Launch(); Step ...

  4. Saltstack pillar组件

     pillar组件 pillar也是Saltstack最重要的组件之一,其作用是定义与被控主机相关的任何数据,定义好的数据可以被其他组件使用,如模板.state.API等.在pillar中定义的数据与 ...

  5. 使用 Ant 自动生成项目构建版本

    引言 对 于多版本项目,要提供新版本来跟上新功能或缺陷报告增加的速度,并同时仍然保持可接受的质量水平,可能是一项不小的挑战.构建自动化可确保准确性和消除人 为错误的可能性,从而部分地解决此问题.自动化 ...

  6. Linux系统改变ls文件和文件夹颜色方法

    本人之前就针对蓝色文件夹的颜色  我是这样修改的:    cp /etc/DIR_COLORS   ~/.dir_colors vim   ~/.dir_colors   , 将DIR 01;33   ...

  7. 一起找bug

    帮同学找的一个bug,错误代码如下: package dai_test; public class Test1 { public static void main(String[] args) { / ...

  8. app的meta

    <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> < ...

  9. iframe框架嵌套技巧(全屏,去双滚动条)

    一般情况下我们很少用到iframe(框架),但有些特殊的情况下我们不得不使用iframe,那么或许或遇到嵌套内容不全屏,网页周围有边框,双滚动条等等情况,下面来说一下处理技巧. 全屏与边框处理: &l ...

  10. LYDSY模拟赛day9 2048

    /* 大模拟题,做的时候思路还是比较清晰的 */ #include<iostream> #include<cstdio> #include<string> #inc ...