Apache Commons IO組件介紹使用
[導(dǎo)讀]
Apache Commons IO組件介紹使用
介紹
java io操作是開發(fā)中比較常用的技術(shù),但是如果每次都使用原生的IO流來操作那么會(huì)顯得很不比較繁瑣,
因此我們可以借助apache com
Apache Commons IO組件介紹使用
介紹
核心工具類
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?
總結(jié)
組件
功能介紹
BeanUtils
提供了對(duì)于JavaBean進(jìn)行各種操作,克隆對(duì)象,屬性等等
Codec
處理常用的編碼方法的工具類包 例如DES、SHA1、MD5、Base64等.
Collections
java集合框架操作
DBCP
提供數(shù)據(jù)庫(kù)連接池服務(wù).
DbUtils
提供對(duì)jdbc 的操作封裝來簡(jiǎn)化數(shù)據(jù)查詢和記錄讀取操作.
Email
java發(fā)送郵件 對(duì)javamail的封裝.
FileUpload
提供文件上傳功能.
HttpClien
提供HTTP客戶端與服務(wù)器的各種通訊操作. 現(xiàn)在已改成HttpComponents
IO
io工具的封裝
Lang
Java基本對(duì)象方法的工具類包 如:StringUtils,ArrayUtils等等
Logging
提供的是一個(gè)Java 的日志接口.
Validator
提供了客戶端和服務(wù)器端的數(shù)據(jù)驗(yàn)證框架.
參考
介紹
java io操作是開發(fā)中比較常用的技術(shù),但是如果每次都使用原生的IO流來操作那么會(huì)顯得很不比較繁瑣,
因此我們可以借助apache commons io包下工具類來幫我們實(shí)現(xiàn)一些常用的操作。
比如:拷貝、將流轉(zhuǎn)為字符串等常用功能
備注:apache commons io包里的代碼其實(shí)并不復(fù)雜,我們可以看看它的源碼研究下人家是怎么寫的,可以參考一下。
核心工具類
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 streamsFileUtils類
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?
總結(jié)
使用commons io可以提供我們更便捷的基本操作流方式,我們應(yīng)該去看下它的實(shí)現(xiàn)源碼,雖然比較簡(jiǎn)單但是也值得參考。
復(fù)雜情況下還是需要我們自己寫。
Apache Commons下都是些日常開發(fā)會(huì)用到的一些組件,我們應(yīng)該好好研究一下,起碼對(duì)初中級(jí)的程序員還是很有幫助的
參考
1、http://commons.apache.org/proper/commons-io/





