本文共 1895 字,大约阅读时间需要 6 分钟。
本工具类提供了一系列文件及目录操作功能,涵盖文本文件操作、目录管理、文件操作等内容,适用于文件管理中常见需求。
public String readTxt(String filePathAndName, String encoding) throws IOException
public String createFolder(String folderPath)
public String createFolders(String folderPath, String paths)
c:/myfolder a|b|c
c:/myfolder/a/b/c
public void createFile(String filePathAndName, String fileContent)
public void createFile(String filePathAndName, String fileContent, String encoding)
public boolean delFile(String filePathAndName)
public void delFolder(String folderPath)
public void copyFile(String oldPathFile, String newPathFile)
public void copyFolder(String oldPath, String newPath)
public void moveFile(String oldPath, String newPath)
public void moveFolder(String oldPath, String newPath)
// 调用示例String paths = "a|b|c";String folderPath = "c:/myfolder";String resultPath = createFolders(folderPath, paths); // 返回 c:/myfolder/a/b/c
String fileContent = "欢迎使用文件操作工具!";createFile("c:/myfile.txt", fileContent);
// 需要复制 directory/ 到 newDirectory/copyFolder("directory/", "newDirectory/");
本工具类代码涵盖了Java文件操作的主要场景,适合开发中常用功能模块,方便日常工作和开发复用。
转载地址:http://vnguk.baihongyu.com/