最近在学commons.io,记录如下:
commons.io包含几个package:
让顺序来,先学习第一个包。
1. FileSystemUtils类提供一些静态的工具方法,例如查看磁盘的freespace。实现是和操作系统os相关,例如window下通过进程执行命令行下dir操作,通过截取最后的数字部分返回得到。
2. FilenameUtils是和文件名(路径)相关的类,可以区分转换windows或者unix的分隔符“/""\\";有normalize方法用于处理//./../。concat将路径和基本路径连接,再调用normalize。还有directonaryContains判断两个两个路径是否包含。
另外包含一些对下面的处理:主要是get方法
the prefix - C:\
the path - dev\project\
the full path - C:\dev\project\
the name - file.txt
the base name - file
the extension - txt
3. IOcase类大小写是否敏感,主要用于比较时候的一个标准。
4. ThreadMonitor类主要实现一个定时器线程,实现runnable接口,控制其他线程时,设为daemon。
public static Thread start(Thread thread, long timeout) {
Thread monitor = null;
if (timeout > 0) {
ThreadMonitor timout = new ThreadMonitor(thread, timeout);
monitor = new Thread(timout, ThreadMonitor.class.getSimpleName());
monitor.setDaemon(true);
monitor.start();
}
return monitor;
}
5. FileDeleteStrategy类如其名,删除策略,normal or force.删除会用到下面的类。
6. FileUtils类
这个类负责文件的一些主要操作,读写增删等等;