一、前言
基于commons-io源码包org.apache.commons.io.FileUtils定义FileSystemUtils文件系统工具类,实现指定路径文件删除delete、指定路径文件复制copy等操作,源码示例如下。
二、源码示例
import java.io.File;@b@import java.io.IOException;@b@import org.apache.commons.io.FileUtils;@b@import org.apache.maven.plugin.MojoExecutionException;@b@@b@public class FileSystemUtils@b@{@b@ public static void delete(String srcDirectoryPath)@b@ throws MojoExecutionException@b@ {@b@ try@b@ {@b@ FileUtils.deleteDirectory(new File(srcDirectoryPath));@b@ }@b@ catch (IOException IOex)@b@ {@b@ throw new MojoExecutionException("Error in deleting the directory", IOex);@b@ }@b@ }@b@@b@ public static void copy(String srcDirectoryPath, String destDir) throws MojoExecutionException@b@ {@b@ try@b@ {@b@ FileUtils.copyDirectory(new File(srcDirectoryPath), new File(destDir));@b@ }@b@ catch (IOException IOex)@b@ {@b@ throw new MojoExecutionException("Error in coping the directory", IOex);@b@ }@b@ }@b@}