当前位置:首页 > 芯闻号 > 充电吧
[导读] Apache Commons IO组件介绍使用 介绍 java io操作是开发中比较常用的技术,但是如果每次都使用原生的IO流来操作那么会显得很不比较繁琐, 因此我们可以借助apache com

Apache Commons IO组件介绍使用
介绍
java io操作是开发中比较常用的技术,但是如果每次都使用原生的IO流来操作那么会显得很不比较繁琐,
因此我们可以借助apache commons io包下工具类来帮我们实现一些常用的操作。

比如:拷贝、将流转为字符串等常用功能
备注:apache commons io包里的代码其实并不复杂,我们可以看看它的源码研究下人家是怎么写的,可以参考一下。

核心工具类

IOUtils类

General IO stream manipulation utilities
This class provides static utility methods for input/output operations.

All the methods in this class that read a stream are buffered internally.
This means that there is no cause to use a BufferedInputStream or BufferedReader. 
The default buffer size of 4K has been shown to be efficient in tests.

备注:IOUtils主要提供更便捷的操作流的方法    

主要方法

toXxx/read - these methods read data from a streamwrite - these methods write data to a streamcopy - these methods copy all the data from one stream to anothercontentEquals - these methods compare the content of two streams

FileUtils类

General file manipulation utilities.
Facilities are provided in the following areas
备注:主要提供方便操作文件/目录的方法

主要方法 


writing to a file 
reading from a file 
make a directory including parent directories 
copying files and directories 
deleting files and directories 
converting to and from a URL 
listing files and directories by filter and extension 
comparing file content 
file last changed date 
calculating a checksum 


总结
使用commons io可以提供我们更便捷的基本操作流方式,我们应该去看下它的实现源码,虽然比较简单但是也值得参考。
复杂情况下还是需要我们自己写。

Apache Commons下都是些日常开发会用到的一些组件,我们应该好好研究一下,起码对初中级的程序员还是很有帮助的
组件 功能介绍 BeanUtils 提供了对于JavaBean进行各种操作,克隆对象,属性等等 Codec 处理常用的编码方法的工具类包 例如DES、SHA1、MD5、Base64等. Collections java集合框架操作 DBCP 提供数据库连接池服务. DbUtils 提供对jdbc 的操作封装来简化数据查询和记录读取操作. Email java发送邮件 对javamail的封装. FileUpload 提供文件上传功能. HttpClien 提供HTTP客户端与服务器的各种通讯操作. 现在已改成HttpComponents IO io工具的封装 Lang Java基本对象方法的工具类包 如:StringUtils,ArrayUtils等等 Logging 提供的是一个Java 的日志接口. Validator 提供了客户端和服务器端的数据验证框架.
参考

1、http://commons.apache.org/proper/commons-io/



本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭