依赖
<dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.4</version></dependency>
FilenameUtils使用示例
import org.apache.commons.io.FilenameUtils;public class IODemo { public static void main(String[] args) { String filename = "/root/name.txt"; System.out.println(FilenameUtils.getName(filename)); // name.txt System.out.println(FilenameUtils.getBaseName(filename)); // name System.out.println(FilenameUtils.getExtension(filename)); // txt }}