java的初学者,准备通读各种高水平源代码,提升能力。

为了避免自己的惰性,写博客。

版本:2.5

开发平台:netbeans。

今天是第一天,网上先看个例子:http://www.importnew.com/13715.html 根据例子,去深入到源代码。

org.apache.commons.io包中有很多工具类,里面多数类都是完成文件操作以及字符串比较的功能,下面列举了一下常用的工具类: FilenameUtils 这个工具类是用来处理文件名(译者注:包含文件路径)的,他可以轻松解决不同操作系统文件名称规范不同的问题(比如windows和Unix)(在Unix系统以及Linux系统中文件分隔符是“/”,不支持”\“,windows中支持”\“以及”/“)。

 FileUtils提供文件操作(移动文件,读取文件,检查文件是否存在等等)的方法。  IOCase提供字符串操作以及比较的方法。
 FileSystemUtils:提供查看指定目录剩余空间的方法。
 
 
import java.io.File;
import java.io.IOException; import org.apache.commons.io.FileSystemUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.LineIterator;
import org.apache.commons.io.IOCase; public final class UtilityExample { // We are using the file exampleTxt.txt in the folder ExampleFolder,
// and we need to provide the full path to the Utility classes.
private static final String EXAMPLE_TXT_PATH =
"C:UsersLilykosworkspaceApacheCommonsExampleExampleFolderexampleTxt.txt"; private static final String PARENT_DIR =
"C:UsersLilykosworkspaceApacheCommonsExample"; public static void runExample() throws IOException {
System.out.println("Utility Classes example..."); // FilenameUtils System.out.println("Full path of exampleTxt: " +
FilenameUtils.getFullPath(EXAMPLE_TXT_PATH)); System.out.println("Full name of exampleTxt: " +
FilenameUtils.getName(EXAMPLE_TXT_PATH)); System.out.println("Extension of exampleTxt: " +
FilenameUtils.getExtension(EXAMPLE_TXT_PATH)); System.out.println("Base name of exampleTxt: " +
FilenameUtils.getBaseName(EXAMPLE_TXT_PATH)); // FileUtils // We can create a new File object using FileUtils.getFile(String)
// and then use this object to get information from the file.
File exampleFile = FileUtils.getFile(EXAMPLE_TXT_PATH);
LineIterator iter = FileUtils.lineIterator(exampleFile); System.out.println("Contents of exampleTxt...");
while (iter.hasNext()) {
System.out.println("t" + iter.next());
}
iter.close(); // We can check if a file exists somewhere inside a certain directory.
File parent = FileUtils.getFile(PARENT_DIR);
System.out.println("Parent directory contains exampleTxt file: " +
FileUtils.directoryContains(parent, exampleFile)); // IOCase String str1 = "This is a new String.";
String str2 = "This is another new String, yes!"; System.out.println("Ends with string (case sensitive): " +
IOCase.SENSITIVE.checkEndsWith(str1, "string."));
System.out.println("Ends with string (case insensitive): " +
IOCase.INSENSITIVE.checkEndsWith(str1, "string.")); System.out.println("String equality: " +
IOCase.SENSITIVE.checkEquals(str1, str2)); // FileSystemUtils
System.out.println("Free disk space (in KB): " + FileSystemUtils.freeSpaceKb("C:"));
System.out.println("Free disk space (in MB): " + FileSystemUtils.freeSpaceKb("C:") / );
}
}

下一次 就分析 FilenameUtils类。

.apache.commons.io 源代码学习(一)的更多相关文章

  1. .apache.commons.io 源代码学习(二)FilenameUtils类

    FilenameUtils是apache common io中一个独立的工具类,对其他没有依赖,看其源代码的import即可知道. import java.io.File;import java.io ...

  2. org.apache.commons.io——FileUtils学习笔记

    FileUtils类的应用 1.写入一个文件: 2.从文件中读取: 3.创建一个文件夹,包括文件夹: 4.复制文件和文件夹: 5.删除文件和文件夹: 6.从URL地址中获取文件: 7.通过文件过滤器和 ...

  3. Apache Commons IO之FileUtils的常用方法

    Apache Commons IO 在学习io流的时候研究(翻译)了一下这个,只有FileUtils的某些方法,并不全面,还请谅解 org.apache.commons.io 这个包下定义了基于 st ...

  4. IO与文件读写---使用Apache commons IO包提高读写效率

    觉得很不错,就转载了, 作者: Paul Lin 首先贴一段Apache commons IO官网上的介绍,来对这个著名的开源包有一个基本的了解:Commons IO is a library of ...

  5. Apache Commons IO入门教程(转)

    Apache Commons IO是Apache基金会创建并维护的Java函数库.它提供了许多类使得开发者的常见任务变得简单,同时减少重复(boiler-plate)代码,这些代码可能遍布于每个独立的 ...

  6. [转]Apache Commons IO入门教程

    Apache Commons IO是Apache基金会创建并维护的Java函数库.它提供了许多类使得开发者的常见任务变得简单,同时减少重复(boiler-plate)代码,这些代码可能遍布于每个独立的 ...

  7. apache.commons.io.FileUtils的常用操作

    至于相关jar包可以到官网获取 http://commons.apache.org/downloads/index.html package com.wz.apache.fileUtils; impo ...

  8. apache.commons.io.IOUtils: 一个很方便的IO工具库(比如InputStream转String)

    转换InputStream到String, 比如 //引入apache的io包 import org.apache.commons.io.IOUtils; ... ...String str = IO ...

  9. Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.FileUtils

    1.错误叙述性说明 警告: Could not create JarEntryRevision for [jar:file:/D:/MyEclipse/apache-tomcat-7.0.53/web ...

随机推荐

  1. 云计算之路-阿里云上:愚人节被阿里云OCS愚

    今天是愚人节,而我们却被阿里云OCS愚,很多地方的缓存一直不过期,造成很多页面中的数据一直不更新.这篇博文将向您分享我们这两天遇到的OCS问题. 阿里云OCS(Open Cache Service)是 ...

  2. PowerDesigner常用功能总结

    1.PowerDesigner设计表时显示注释列Comment 选中准备编辑的表,[右键]->[Properties]->[Columns]->[Customize Columns ...

  3. 《Cracking the Coding Interview》——第11章:排序和搜索——题目8

    2014-03-21 22:23 题目:假设你一开始有一个空数组,你在读入一些整数并将其插入到数组中,保证插入之后数组一直按升序排列.在读入的过程中,你还可以进行一种操作:查询某个值val是否存在于数 ...

  4. [转]LVS+Keepalived负载均衡配置

    简介 来源:https://www.cnblogs.com/MacoLee/p/5858995.html lvs一般是和keepalived一起组合使用的,虽然也可以单独使用lvs,但配置比较繁琐,且 ...

  5. 【已解决】UBuntu16.04软件中心更新后只有桌面

    出现问题之前 安装好系统之后,成功启动系统,根据软件中心提示,升级电脑安装的软件,如下图所示.点击install(安装)开始更新,之后无任何提示,其实这个时候已经出现了升级异常. 呈现问题 操作步骤一 ...

  6. springboot09 事务 H2数据库

    一.事务 1. 事务介绍 事务可以包含多个操作步骤 , 如果有一个步骤失败,那么这一组都以失败告终. 事务是指包含多个微小逻辑单元的一组操作, 只要其中有一个逻辑失败了,那么这一组操作就全部以失败告终 ...

  7. 冒泡排序js

    //    冒泡排序     var a = [1,3,2,4,5,3,2,1,4,6,7,7,6,6];     var b =[];     for(var i=0;i<a.length;i ...

  8. HDU 2295 Radar (二分 + Dancing Links 重复覆盖模型 )

    以下转自 这里 : 最小支配集问题:二分枚举最小距离,判断可行性.可行性即重复覆盖模型,DLX解之. A*的启发函数: 对当前矩阵来说,选择一个未被控制的列,很明显该列最少需要1个行来控制,所以ans ...

  9. 团队项目-第四次Scrum 会议

    时间:10.26 时长:30分钟 地点:线上 工作情况 团队成员 已完成任务 待完成任务 解小锐 编写project和projectGenerator类 编写下一步的规格说明 陈鑫 采用creator ...

  10. Beta

    目录 过去存在的问题 任务分工 规范 后端总结 卉卉 家灿 前端总结 绪佩 青元 恺琳 宇恒 丹丹 算法&API接口 家伟 鸿杰 一好 文档&博客撰写 政演 产品功能 我们已经坐了哪些 ...