處理Java IO的一些工具類包 Commons IO 2.2 發布

openkk 12年前發布 | 16K 次閱讀 Commons

Apache Commons IO 2.2 發布了,在 2.1 版本基礎上增加 15 個新特性,1個改動以及修復8個bug,詳情請看

https://commons.apache.org/io/changes-report.html#a2.2

Commons項目中用來處理Java 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);
 }
http://commons.apache.org/io/

 本文由用戶 openkk 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!