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. Result Maps collection does not contain value for xxxx

    这是mybatis查询返回值的错误,我在做一个查询数值的方法,但是我是这样写的: <select id="findSize" resultMap="long&quo ...

  2. Postman-CI集成Jenkins(3)

    Postman-CI集成Jenkins(3) Postman-简单使用 Postman-进阶使用 Postman-CI集成Jenkins Newman 官方说明:Postman's command-l ...

  3. centso下如何解压RAR文件

    tar -xvf rarlinux-3.9.3.tar.gz cd rar   make 看见下面这些信息就是安装成功了 mkdir -p /usr/local/bin mkdir -p /usr/l ...

  4. Spring+SpringMVC+MyBatis+Redis框架学习笔记

    在Java互联网中,以Spring+Spring MVC+MyBatis (SSM) 作为主流框架. SSM+Redis的结构图 在这种框架系统中: Spring IoC 承担了一个资源管理.整合.即 ...

  5. java5初学

    1.Eclipse快捷键 alt + / 代码提示,例如自动创建main方法ctrl + d 删除当前行ctrl + alt + up/down 复制当前行alt + up/down 交换行ctrl ...

  6. Python全栈工程师

    ParisGabriel       Python 入门基础   print(“hello world”)变量 : 存储信息的,日后被调用.修改操作常量: 固定不变的量,字母大写命名规则:1. 字母数 ...

  7. inspect流程

    当node节点state为manage时,可执行inspector ironic node-set-provision-state <node_uuid> manage ironic no ...

  8. 【志银】NYOJ《题目524》A-B Problem

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=860 My思路: 先用两个字符串储存这两个实数,然后再用另外两个字符串储存去掉符号和前后多 ...

  9. PCA学习笔记

    主成分分析(Principal Component Analysis,简称PCA)是最常用过的一种降维方法 在引入PCA之前先提到了如何使用一个超平面对所有的样本进行恰当的表达? 即若存在这样的超平面 ...

  10. Linux大小端模式转换函数

    转自 http://www.cnblogs.com/kungfupanda/archive/2013/04/24/3040785.html 不同机器内部对变量的字节存储顺序不同,有的采用大端模式(bi ...