.apache.commons.io 源代码学习(二)FilenameUtils类
2024-10-21 06:03:50
FilenameUtils是apache common io中一个独立的工具类,对其他没有依赖,看其源代码的import即可知道。
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Stack;
这个类的目标是:
When dealing with filenames you can hit problems when moving from a Windows
based development machine to a Unix based production machine.
This class aims to help avoid those problems.
我们在看看uml类图;
我们可以注意到,其提供的方法,基本都是静态的,所以,这个类我认为,大部分使用的时候,都不需要实例化,典型的工具类。
而其目标是在windows系统和unix系统之间的文件名转换,因此,最初就是定义了windows和unix系统的文件的分隔符
public static final char EXTENSION_SEPARATOR = '.';
public static final String EXTENSION_SEPARATOR_STR = Character.toString(EXTENSION_SEPARATOR);
private static final char UNIX_SEPARATOR = '/';
private static final char WINDOWS_SEPARATOR = '\\';
private static final char SYSTEM_SEPARATOR = File.separatorChar;
private static final char OTHER_SEPARATOR; static {
if (isSystemWindows()) {
OTHER_SEPARATOR = UNIX_SEPARATOR;
} else {
OTHER_SEPARATOR = WINDOWS_SEPARATOR;
}
} static boolean isSystemWindows() {
return SYSTEM_SEPARATOR == WINDOWS_SEPARATOR;
}
这个,判断是否windows的方法很不错。
最新文章
- C#邮箱发送验证码
- SpringMVC对日期类型的转换
- 深入理解JS的delete
- 重新初始化RAC的OCR盘和Votedisk盘,修复RAC系统
- http://www.cnblogs.com/softidea/p/5631763.html
- [CLR via C#]18. Attribute
- Android AIDL使用详解
- Eclipse 常用设置
- 网站seo新手快速提升自己的技巧
- MyBatis 拦截器 (实现分页功能)
- 腾讯2014在广州站实习生offer经验(TEG-开发背景)
- 使用PowerDesigner画ER图详细教程
- linq使用日记
- Java复习2.程序内存管理
- jmeter接口测试-GET请求路径中包含特殊字符或中文导致Response400报错
- Presto集群部署和配置
- Spring Cloud构建微服务架构(五)服务网关
- MSSQL 数据库 buildindex 出错
- 分布式缓存技术redis系列(四)——redis高级应用(集群搭建、集群分区原理、集群操作)
- 手工生成AWR报告方法记录