Apache Commons IO 2.1 发布
fmms 13年前
Commons项目中用来处理IO的一些工具类包,下面是一些示例代码: <pre class="brush:java; toolbar: true; auto-links: false;">//直接将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); }</pre> <p>Apache Commons IO 2.1 发布了,这是从 2.0.1 版本直接升级,包括7个新特性以及一些bug修复。</p> <p><strong>新特性:</strong></p> <p>o Use standard Maven directory layout <br /> o Add IOUtils API toString for URL and URI to get contents <br /> o Add API FileUtils.copyFile(File input, OutputStream output)<br /> o FileAlterationObserver has no getter for FileFilter<br /> o Add FileUtils.getFile API with varargs parameter<br /> o Add new APPEND parameter for writing string into files<br /> o Add new read method "toByteArray" to handle InputStream with known size.</p> <p><strong>修复的bug:</strong></p> <p>o Dubious use of mkdirs() return code<br /> o ReaderInputStream enters infinite loop when it encounters an unmappable character<br /> o FileUtils.moveFile() JavaDoc should specify FileExistsException thrown<br /> o ClassLoaderObjectInputStream does not handle Proxy classes<br /> o Tailer returning partial lines when reaching EOF before EOL<br /> o FileUtils.copyFile() throws IOException when copying large files to a shared directory (on Windows)<br /> o FileSystemUtils.freeSpaceKb throws exception for Windows volumes with no visible files.</p> <p>下载地址:<a href="/misc/goto?guid=4958192953776425315" target="_blank">http://commons.apache.org/io/download_io.cgi</a></p>