/**
* 文件操作工具类
* 对文件进行拷贝、给文件夹打tar包等操作
* @author z60959
* @version TopEng-CSP V600R003
* @since TopEng-CSP V600R003
*/
public final class FileUtil
{
/**
* 私有构造方法,不允许实例化
*/
private FileUtil()
{
}
/**
* 创建新文件夹
* 如果已经存在同名文件夹,则不重新创建
* @param folderPath 文件路径
* @throws IOException 抛出IO异常
*/
public static void createFolder(String folderPath) throws IOException
{
// 先创建新的目标文件
File file = new File(folderPath);
if (!file.exists())
{
file.mkdirs();
}
}
/**
* 创建新文件
* 如果已经存在同名文件,则先删除,再创建新文件
* @param filePath 文件路径
* @throws IOException 抛出IO异常
*/
public static void createNewFile(String filePath) throws IOException
{
// 先创建新的目标文件
File file = new File(filePath);
if (file.exists())
{
file.delete();
}
// 先创建父目录
file.getParentFile().mkdirs();
// 创建目标文件
file.createNewFile();
}
文件操作工具类FileUtil(1)
最新推荐文章于 2021-09-13 10:14:26 发布