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

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

File --> InputStream

InputStream in = new FileInputStream(file);

InputStream --> File

public void inputstreamtofile(InputStream ins,File file){
   OutputStream os = new FileOutputStream(file);
   int bytesRead = 0;
   byte[] buffer = new byte[8192];
   while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
      os.write(buffer, 0, bytesRead);
   }
   os.close();
   ins.close();
}

String--> InputSource

InputSource is=new InputSource(new StringReader(xmlStr))

String inputStream file转化的更多相关文章

  1. Java中InputStream和String之间的转化

    https://blog.csdn.net/lmy86263/article/details/60479350 在Java中InputStream和String之间的转化十分普遍,本文主要是总结一下转 ...

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

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

  3. Java InputStream、String、File相互转化 --- good

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

  4. 30天C#基础巩固------面向鸭子编程,关于string和File的练习

         面向对象编程就是面向抽象的父类进行编程,具体的实现不用考虑,由子类决定.<经典的说法--面向鸭子编程> eg:鸭子的编程,<对于多态的理解>     我们都习惯把使用 ...

  5. Timestame类型和String 类型的转化

    Timestame类型和String 类型的转化 String转化为Timestamp: SimpleDateFormat df = new SimpleDateFormat("yyyy-M ...

  6. java常用string inputStream转换

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

  7. Junit 注解 类加载器 .动态代理 jdbc 连接池 DButils 事务 Arraylist Linklist hashset 异常 哈希表的数据结构,存储过程 Map Object String Stringbufere File类 文件过滤器_原理分析 flush方法和close方法 序列号冲突问题

    Junit 注解 3).其它注意事项: 1).@Test运行的方法,不能有形参: 2).@Test运行的方法,不能有返回值: 3).@Test运行的方法,不能是静态方法: 4).在一个类中,可以同时定 ...

  8. C# byte[]数组和string的互相转化 (四种方法)

    C# byte[]数组和string的互相转化 (四种方法) 第一种 [csharp] view plain copy string str = System.Text.Encoding.UTF8.G ...

  9. CString/string 区别及其转化

    CString/string 区别及其转化 利用MFC进行编程时,我们从对话框中利用GetWindowText得到的字符串是CString类型,CString是属于MFC的类.而一些标准C/C++库函 ...

随机推荐

  1. Flex中 Array 的IndexOf 的作用

    Flex中 Array 的IndexOf 的作用 1.说明    indexOf用于在索引中从小到大查找,假设查得到就返回索引值,查不到就返回-1: 2.实例 (1)设计源代码 <?xml ve ...

  2. 提升 composer 的执行速读

    常常遇到 php composer.phar update 等待一二十分钟还没有更新完成的情况. 提升速读的方法: 1. 升级PHP 版本到5.4以上 2. 删除文件夹Vender(或者重命名),之后 ...

  3. redo log write和flush

    http://bbs.chinaunix.net/thread-1753130-1-1.html 在事务提交时innobase会调用ha_innodb.cc 中的innobase_commit,而in ...

  4. CISCO 双线接入MAP配置详解

      随着我国宽带技术的普及,各个公司都会有一至二条Internet接入线路,这些线路可能由电信.网通.长宽.联通等不同的IS提供,尽管他们在局端采用的技术可能有不同,但对客户而言都是同样接入方式,以太 ...

  5. HBase Error: connection object not serializable

    HBase Error: connection object not serializable 想在spark driver程序中连接HBase数据库,并将数据插入到HBase,但是在spark集群提 ...

  6. couldn't set tty to ppp discipline invalid argument

    参考: http://pptpclient.sourceforge.net/howto-diagnosis.phtml#conventions http://blog.chinaunix.net/ui ...

  7. iOS语音合成

    苹果公司在iOS7中推出了语音合成的技术,无需网络环境也可以实现语音合成. iOS7语音合成的主要的API如下: 1.AVSpeechUtterance,是语音合成的基本单位,它封装影响语音合成的需要 ...

  8. B. Fox And Two Dots

    B. Fox And Two Dots time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. android 编写动画

    1.在编写动画的时候需要新建一个xml 新建的步骤是选中res单击右键选择Android resource file 然后弹出一个框 ,然后再Resource Type 里面选择Animation 然 ...

  10. c# 友元程序集

    在团队开发中,如果一个程序集中要调用另外一个程序集,但是要被调用的那个程序集又不想用public来公开自己的类, 那么怎么办,就是用最后一种internal来用来做类的可见性了. 下面来看一个简单例子 ...