Apache Commons IO组件介绍使用

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/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值