您的位置:首页 > 运维架构 > Apache

Apache Commons IO组件介绍使用

2017-09-05 11:32 369 查看


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 stream
write - these methods write data to a stream
copy - these methods copy all the data from one stream to another
contentEquals - 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等.
Collectionsjava集合框架操作
DBCP提供数据库连接池服务.
DbUtils提供对jdbc 的操作封装来简化数据查询和记录读取操作.
Emailjava发送邮件 对javamail的封装.
FileUpload提供文件上传功能.
HttpClien提供HTTP客户端与服务器的各种通讯操作. 现在已改成HttpComponents
IOio工具的封装
LangJava基本对象方法的工具类包 如:StringUtils,ArrayUtils等等
Logging提供的是一个Java 的日志接口.
Validator提供了客户端和服务器端的数据验证框架.


参考

1、http://commons.apache.org/proper/commons-io/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: