Commons-IO 2.4 发布
jopen 12年前
<p><a href="/misc/goto?guid=4958347259834415024" target="_blank">Commons-io </a>2.4 发布了,Commons项目中用来处理IO的一些工具类包,</p> <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> <br /> <br /> 该版本改进记录包括: <p></p> <p><strong>New features:</strong><br /> o IO-269: Tailer locks file from deletion/rename on Windows. Thanks to sebb.<br /> o IO-333: Export OSGi packages at version 1.x in addition to 2.x. Thanks to fmeschbe.<br /> o IO-320: Add XmlStreamReader support for UTF-32. Thanks to ggregory.<br /> o IO-331: BOMInputStream wrongly detects UTF-32LE_BOM files as UTF-16LE_BOM files in method getBOM(). Thanks to ggregory.<br /> o IO-327: Add byteCountToDisplaySize(BigInteger). Thanks to ggregory.<br /> o IO-326: Add new FileUtils.sizeOf[Directory] APIs to return BigInteger. Thanks to ggregory, kinow.<br /> o IO-325: Add IOUtils.toByteArray methods to work with URL and URI. Thanks to raviprak.<br /> o IO-324: Add missing Charset sister APIs to method that take a String charset name. Thanks to raviprak.<br /> <br /> <strong>Fixed Bugs:</strong><br /> o IO-336: Yottabyte (YB) incorrectly defined in FileUtils. Thanks to rleavelle.<br /> o IO-279: Tailer erroneously considers file as new. Thanks to Sergio Bossa, Chris Baron.<br /> o IO-335: Tailer#readLines - incorrect CR handling.<br /> o IO-334: FileUtils.toURLs throws NPE for null parameter; document the behavior.<br /> o IO-332: Improve tailer's reading performance. Thanks to liangly.<br /> o IO-279: Improve Tailer performance with buffered reads (see IO-332).<br /> o IO-329: FileUtils.writeLines uses unbuffered IO. Thanks to tivv.<br /> o IO-319: FileUtils.sizeOfDirectory follows symbolic links. Thanks to raviprak.</p>