package com.test2;
/**
* 文件处理类
* @author nt
*
*/
public class FileUtil {
/**
* 获取文件名
* @param path
* @return
*/
public static String getFileName(String path) {
int beginIndex = path.lastIndexOf("\\");
int endIndex = path.lastIndexOf(".");
String fileName = path.substring(beginIndex + 1, endIndex);
return fileName;
}
/**
* 获取文件后缀
* @param path
* @return
*/
public static String getFileSuffix(String path) {
int endIndex = path.lastIndexOf(".");
String suffix = path.substring(endIndex + 1);
return suffix;
}
/**
* 打印文件的后缀
* @param path
*/
public static void printFileDir(String path) {
String[] dirs = path.split("\\\\");
for (int i = 0; i < dirs.length; i++) {
for (int j = 0; j < i; j++) {
System.out.print("\t");
}
System.out.println((i == 0 ? "" : "-") + dirs[i]);
}
}
}
FileUtil
最新推荐文章于 2022-02-15 20:39:15 发布