Apache Commons IO 2.1 發布
Commons項目中用來處理IO的一些工具類包,下面是一些示例代碼:
//直接將IO流轉成字符串
InputStream in = new URL( "http://jakarta.apache.org" ).openStream();
try {
System.out.println( IOUtils.toString( in ) );
} finally {
IOUtils.closeQuietly(in);
}
//讀取文本文件的所有行
File file = new File("/commons/io/project.properties");
List lines = FileUtils.readLines(file, "UTF-8");
//路徑處理
String filename = "C:/commons/io/../lang/project.xml";
String normalized = FilenameUtils.normalize(filename);
// result is "C:/commons/lang/project.xml"
//獲取目錄空間
long freeSpace = FileSystemUtils.freeSpace("C:/");
//打印文件的所有行
LineIterator it = FileUtils.lineIterator(file, "UTF-8");
try {
while (it.hasNext()) {
String line = it.nextLine();
/// do something with line
}
} finally {
LineIterator.closeQuietly(iterator);
}
Apache Commons IO 2.1 發布了,這是從 2.0.1 版本直接升級,包括7個新特性以及一些bug修復。
新特性:
o Use standard Maven directory layout
o Add IOUtils API toString for URL and URI to get contents
o Add API FileUtils.copyFile(File input, OutputStream output)
o FileAlterationObserver has no getter for FileFilter
o Add FileUtils.getFile API with varargs parameter
o Add new APPEND parameter for writing string into files
o Add new read method "toByteArray" to handle InputStream with known size.
修復的bug:
o Dubious use of mkdirs() return code
o ReaderInputStream enters infinite loop when it encounters an unmappable character
o FileUtils.moveFile() JavaDoc should specify FileExistsException thrown
o ClassLoaderObjectInputStream does not handle Proxy classes
o Tailer returning partial lines when reaching EOF before EOL
o FileUtils.copyFile() throws IOException when copying large files to a shared directory (on Windows)
o FileSystemUtils.freeSpaceKb throws exception for Windows volumes with no visible files.
下載地址:http://commons.apache.org/io/download_io.cgi