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

Java InputStream、String、File相互转化的更多相关文章

  1. Java InputStream转File

    文件处于磁盘上或者流处于内存中 在输入流有已知的和预处理的数据时,如在硬盘上的文件或者在流处于内存中.这种情况下,不需要做边界校验,并且内存容量条件允许的话,可以简单的读取并一次写入. InputSt ...

  2. Java:String,int相互转化

    int转String int a: a + “”    String.valueOf(a)    Interger.toString(a)    一般使用以上几种方法进行转化 第一种方法效率不好,ja ...

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

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

  4. inputStream、File、Byte、String等等之间的相互转换

    一:inputStream转换 1.inputStream转为byte //方法一 org.apache.commons.io.IOUtils包下的实现(建议) IOUtils.toByteArray ...

  5. @RequestParam注解使用:Name for argument type [java.lang.String] not available, and parameter name information not found in class file either.

    详细错误信息 Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Re ...

  6. java中InputStream String

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

  7. InputStream,String相互转化

    String --> InputStream InputStream String2InputStream(String str){ ByteArrayInputStream stream = ...

  8. java常用string inputStream转换

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

  9. Java学习笔记——File类之文件管理和读写操作、下载图片

    Java学习笔记——File类之文件管理和读写操作.下载图片 File类的总结: 1.文件和文件夹的创建 2.文件的读取 3.文件的写入 4.文件的复制(字符流.字节流.处理流) 5.以图片地址下载图 ...

随机推荐

  1. Oculus Rift, HTC Vive, SONY PSVR的全面对比

    http://blog.csdn.net/xoyojank/article/details/50927572 这次有幸参加了GDC 2016, 终于把三大设备体验了个遍, 也试玩了很多不错的VR游戏. ...

  2. Educational Codeforces Round 18D(完全二叉树中序遍历&lowbit)

    题目链接:http://codeforces.com/contest/792/problem/D 题意:第一行输入n, q,分别表示给出一颗n个节点的中序遍历满二叉树,后面有q个询问; 接下来有q组形 ...

  3. Metabolic and gut microbial characterization of obesity-prone mice under high-fat diet (文献分享一组-赵容丽)

    题目:高脂饮食下易肥胖小鼠的代谢和肠道微生物特性研究 Metabolic and gut microbial characterization of obesity-prone mice under ...

  4. 字符串最小表示初探 By cellur925

    我们考虑有一个字符串,可以从这个字符串的不同位置出发,把这个字符串大声朗读出来,当到字符串末端的时候再从头开始读,直到回到"梦开始的地方". 设字符串长度为\(n\),那么有\(n ...

  5. [!] No `Podfile' found in the project directory.

    1.cd ios/ 2.vim Podfile(创建Podfile)且输入内容 source'https://github.com/CocoaPods/Specs.git'platform:ios,' ...

  6. python3错误之TypeError: 'dict_items' object is not callable

    这种错误出现在循环结构中套循环结构,而循环时内部循环为字典,外部循环为该字典调用items方法后取到的值,内部循环调用外部循环中遍历的结果: 解决方案: 将外部循环的items()方法调用改为.key ...

  7. 如何使用LESS 深度定制Bootstrap

    一.LESS是什么? Less 是一门 CSS 预处理语言,它扩展了 CSS 语言,增加了变量.Mixin.函数等特性,使 CSS 更易维护和扩展. 中文介绍:http://lesscss.cn/ 有 ...

  8. Jasper_table_resolve multiple copies of table in detail band issue

    resolve method: (1) put table component into the Title band / Page Header band / Summary band, not i ...

  9. jsp第一章 动态网页开发基础

    动态网站可以实现交互功能,如用户注册.信息发布.产品展示.订单管理等等: 动态网页并不是独立存在于服务器的网页文件,而是浏览器发出请求时才反馈网页: 动态网页中包含有服务器端脚本,所以页面文件名常以a ...

  10. 2840 WIKIOI——评测

    2840 WIKIOI——评测 时间限制: 1 s 空间限制: 2000 KB 题目等级 : 白银 Silver       题目描述 Description Wikioi上有一题有N个测试点,时限为 ...