Commons IO is a library of utilities to assist with developing IO functionality. There are four main areas

included:

●Utility classes - with static methods to perform common tasks

●Filters - various implementations of file filters

●Comparators - various implementations of java.util.Comparator for files

●Streams - useful stream, reader and writer implementations

通过IOUtils 我们能够提升IO读写效率。下面是一些简单分析。

IOUtils 输入流复制到 输出流

 Writer write = new FileWriter("c:\\kk.dat");  

 InputStream ins = new FileInputStream(new File("c:\\text.txt"));  

 IOUtils.copy(ins, write);  

 ins.close(); write.close();

copy(InputStream in, OutputStream out )的实现

     public static long copyLarge(final InputStream input, final OutputStream output, final byte[] buffer)
throws IOException {
long count = 0;
int n;
while (EOF != (n = input.read(buffer))) {
output.write(buffer, 0, n);
count += n;
}
return count;
}

可以发现,copy流的方法直接写入而不仅仅是定义OutputStream,这点开发中一定要注意。 ^_^

IOUtils的closeQuietly()方法:

  Unconditionally close an InputStream.

  Equivalent to InputStream.close(), except any exceptions will be ignored. This is typically used in finally blocks.

IO - IOUtils的更多相关文章

  1. apache.commons.io.IOUtils: 一个很方便的IO工具库(比如InputStream转String)

    转换InputStream到String, 比如 //引入apache的io包 import org.apache.commons.io.IOUtils; ... ...String str = IO ...

  2. Commons IO - IOUtils

    IOUtils is a general IO stream manipulation utilities. This class provides static utility methods fo ...

  3. Tomcat中使用commons-io-2.5发生的错误java.lang.ClassNotFoundException: org.apache.commons.io.IOUtils

    关键词:IntelliJ IDEA.Tomcat.commons-io-2.5.jar.java.lang.ClassNotFoundException: org.apache.commons.io. ...

  4. 17-Java-文件上传报错(commons-fileupload包和commons-io包不支持JDK版本:UnsupportedClassVersionError: org/apache/commons/io/IOUtils : Unsupported major.minor version 52.0)

    文件上传报错(commons-fileupload包和commons-io包不支持JDK版本) 这个bug可把我弄惨了!!!我代码是想通过写个文件上传,我写的文件上传需要用到commons-fileu ...

  5. java io流 图片和字符串之间的转换

    package com.yundongsports.arena.controller.basketballsite;import com.yundongsports.arena.ResponseVo. ...

  6. Java程序员的日常—— IOUtils总结

    以前写文件的复制很麻烦,需要各种输入流,然后读取line,输出到输出流...其实apache.commons.io里面提供了输入流输出流的常用工具方法,非常方便.下面就结合源码,看看IOUTils都有 ...

  7. Java IO流学习总结八:Commons IO 2.5-IOUtils

    Java IO流学习总结八:Commons IO 2.5-IOUtils 转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/550519 ...

  8. Hadoop(九)Hadoop IO之Compression和Codecs

    前言 前面一篇介绍了Java怎么去查看数据块的相关信息和怎么去查看文件系统.我们只要知道怎么去查看就行了!接下来我分享的是Hadoop的I/O操作. 在Hadoop中为什么要去使用压缩(Compres ...

  9. 文件输入输出流工具: IOUtils使用总结

    序言 以前写文件的复制很麻烦,需要各种输入流,然后读取line,输出到输出流...其实apache.commons.io里面提供了输入流输出流的常用工具方法,非常方便.下面就结合源码,看看IOUTil ...

随机推荐

  1. hihoCoder#1014 Trie树 (前缀树)

    题目大意:给一本有n个单词的词典,有m次询问,每次询问的是该词典中有多少个单词有共同的某个前缀. 题目分析:在添加单词建立trie的时候,每经过一个节点就意味着该节点和它的各级祖先节点是某个单词的前缀 ...

  2. vimium 使用心得

    首先,建议记住chrom自己的支持的快捷键 https://support.google.com/chrome/answer/157179?hl=zh-Hans&hlrm=en-GB& ...

  3. poj1128 拓扑序(DFS)

    题意:给出一张图,它是由一系列字母框按一定顺序从下到上摆放,因此上面的字母框会覆盖一部分下面的字母框,确保每个字母框的四条边都至少会出现一个点,要求输出所有可行的摆放顺序,字典序从小到大输出. 首先可 ...

  4. 控制文本和外观------CSS Binding(CSS类名绑定)

    <style> .myColor{color:red;font-size:13px} .yourColor{color:green;font-size:34px}</style> ...

  5. Amazon-countDuplicate

    Print the count of duplicate char in a given string in same order. Ex: Input- 'abbaccdbac', Output- ...

  6. Vi个人学习使用心得

    找句首/句末 光标所在行:句首: shift+^; 句末: shift +$; 括号匹配:光标在某一括号上,然后shift+% 快速对齐 针对括号的内容:将括号中的内容全部选中之后(按V后, shif ...

  7. orzdba的安装与使用

    参考:http://code.taobao.org/p/orzdba/src/ http://code.taobao.org/p/myrelay/wiki/index/ http://www.taob ...

  8. ibm硬件知识点

    ibm http://www-03.ibm.com/systems/storage/disk/storwize_v3700/index.html Current software level: Ver ...

  9. 虚拟化之vmware-vcenter

    VMware ESXi.VMware vCenter Server 和 vSphere Client,它们分别是 vSphere 的虚拟化层.管理层和接口层. vcenter server 插件和vc ...

  10. 如何用js检查浏览器是否安装flash插件

    <script type="text/javascript" language="JavaScript"> //Powered By smvv @h ...