package cn.itcast.tmhkcUtils;
import java.io.File;
public class MyFileUtils {
// 获取文件后缀名
public static String getFileExt(String s) {
String s1 = new String();
int i = 0;
int j = 0;
if (s == null)
return null;
i = s.lastIndexOf(".") + 1;
j = s.length();
s1 = s.substring(i, j);
if (s.lastIndexOf(46) > 0)
return s1.toLowerCase();
else
return "";
}
// 获取文件名的名称
public static String getNameWithoutExtension(String fileName) {
return fileName.substring(0, fileName.lastIndexOf("."));
}
/**
*
* @param sPath 需要检查的文件夹路径字符串
* @param sFile 文件的全称 格式为*.***
* @return 返回一个不重复的文件名全称 格式为 *.*
* @throws
*/
public static String newFile(String sPath, String sFile) throws Exception {
if (!sFile.contains("."))
throw new Exception("输入的文件名格式不正确,应该为*.*");
String newFileName = new String();
String
检索目录下是否有重名文件 并返回不重名字符串 Utils
最新推荐文章于 2024-06-09 18:50:26 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)