Apache Commons IO組件介紹使用
介紹
java io操作是開(kāi)發(fā)中比較常用的技術(shù),但是如果每次都使用原生的IO流來(lái)操作那么會(huì)顯得很不比較繁瑣,
因此我們可以借助apache commons io包下工具類來(lái)幫我們實(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下都是些日常開(kāi)發(fā)會(huì)用到的一些組件,我們應(yīng)該好好研究一下,起碼對(duì)初中級(jí)的程序員還是很有幫助的
參考
1、http://commons.apache.org/proper/commons-io/