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. sgu546 Ternary Password

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=546 这题还好,1Y,考虑情况周全,就没问题了,还好提交之前把想到的情况都测试了一遍 ...

  2. JS初学之-自定义属性(索引值)

    重点:1.添加索引值的作用:建立匹配.对应的关系. 比如:使每一个按钮对应数组里的每一张图,arrImg[this.index]. 2.不要在for循环的函数里面使用i. 3.添加索引值的方法aBtn ...

  3. 最大子段和问题,最大子矩阵和问题,最大m子段和问题

    1.最大子段和问题      问题定义:对于给定序列a1,a2,a3……an,寻找它的某个连续子段,使得其和最大.如( -2,11,-4,13,-5,-2 )最大子段是{ 11,-4,13 }其和为2 ...

  4. ps命令详解(转)

    原文地址:http://apps.hi.baidu.com/share/detail/32573968 有时候系统管理员可能只关心现在系统中运行着哪些程序,而不想知道有哪些进程在运行.由于一个应用程序 ...

  5. 如何才能将Faster R-CNN训练起来?

    如何才能将Faster R-CNN训练起来? 首先进入 Faster RCNN 的官网啦,即:https://github.com/rbgirshick/py-faster-rcnn#installa ...

  6. caffe: test code Check failed: K_ == new_K (768 vs. 1024) Input size incompatible with inner product parameters.

    I0327 20:24:22.966171 20521 net.cpp:849] Copying source layer drop7I0327 20:24:22.966179 20521 net.c ...

  7. AWR分析。(shared_pool,sga_size大小设置)

    Execute to Parse 指标反映了执行解析比 其公式为 1-(parse/execute) , 目标为100% 及接近于只 执行而不解析 在oracle中解析往往是执行的先提工作,但是通过游 ...

  8. jQuery UI 对话框(Dialog) - 模态表单

    <!doctype html><html lang="en"><head> <meta charset="utf-8" ...

  9. c# 加密转载 备忘

    public sealed class EncryptUtils { #region Base64加密解密 /// <summary> /// Base64加密 /// </summ ...

  10. Cookielib

    Cookielib模块主要的对象有CookieJar.FileCookieJar.MozillaCookieJar.LWPCookieJar 它们的关系:CookieJar —-派生—->Fil ...