@Test public void testCopy() throws IOException { String basePath = System.getProperty("user.dir") + "/src/test"; FileHelper.copy(new File(basePath + "/java"), new File(basePath + "/resource/temp/copytarget/")); }
public static boolean copy(File resource, File target) throws IOException { if (resource == null) { logger.error("copy resource is null"); return false; } if (resource.isFile()) { return copyFile(resource, target); } File[] files = resource.listFiles(); if (files == null || files.length == 0) { return target.mkdirs(); } target.mkdirs(); for (File file : files) { String targetFilePath = file.getAbsolutePath().substring(resource.getAbsolutePath().length()); File targetFile = new File(target + "/" + targetFilePath); if (file.isDirectory()) { targetFile.mkdirs(); copy(file, targetFile); } else { copyFile(file, targetFile); } } return true; }
FileHelper { public static boolean copy(File resource, File target) throws IOException { if (resource == null) { logger.error("copy resource is null"); return false; } if (resource.isFile()) { return copyFile(resource, target); } File[] files = resource.listFiles(); if (files == null || files.length == 0) { return target.mkdirs(); } target.mkdirs(); for (File file : files) { String targetFilePath = file.getAbsolutePath().substring(resource.getAbsolutePath().length()); File targetFile = new File(target + "/" + targetFilePath); if (file.isDirectory()) { targetFile.mkdirs(); copy(file, targetFile); } else { copyFile(file, targetFile); } } return true; } }
FileHelper { public static boolean copy(File resource, File target) throws IOException { if (resource == null) { logger.error("copy resource is null"); return false; } if (resource.isFile()) { return copyFile(resource, target); } File[] files = resource.listFiles(); if (files == null || files.length == 0) { return target.mkdirs(); } target.mkdirs(); for (File file : files) { String targetFilePath = file.getAbsolutePath().substring(resource.getAbsolutePath().length()); File targetFile = new File(target + "/" + targetFilePath); if (file.isDirectory()) { targetFile.mkdirs(); copy(file, targetFile); } else { copyFile(file, targetFile); } } return true; }  }
FileHelper { public static boolean copy(File resource, File target) throws IOException { if (resource == null) { logger.error("copy resource is null"); return false; } if (resource.isFile()) { return copyFile(resource, target); } File[] files = resource.listFiles(); if (files == null || files.length == 0) { return target.mkdirs(); } target.mkdirs(); for (File file : files) { String targetFilePath = file.getAbsolutePath().substring(resource.getAbsolutePath().length()); File targetFile = new File(target + "/" + targetFilePath); if (file.isDirectory()) { targetFile.mkdirs(); copy(file, targetFile); } else { copyFile(file, targetFile); } } return true; }  static void handlerWithLine(File file, String encoding, ObjectHandler<String> handler); static void processWithLine(File file, String encoding, Collection<E> result, ObjectProcess<String, E> process); static int lineCounts(File file); static List<String> readLines(File file); static List<String> readLines(File file, String encoding); static String readContents(File file); final static boolean createFiles(File file); final static boolean createFiles(File file, boolean isReNew); static boolean write(File file, String str); static boolean write(File file, String str, String encoding); static boolean addWrite(File file, String str); static boolean addWrite(File file, String str, String encoding); static boolean copy(File resource, File target); static boolean copyFile(File file, File targetFile); static boolean cleanFile(File file); static boolean delete(File file); static List<File> listFile(File path); static List<File> listFileSuffix(File dirPath, String postfixs); static List<File> listFileName(File dirPath, String fileName); static List<File> listFileNameIgnoreCase(File dirPath, String fileName); static List<File> listFileFilter(File path, ObjectFilter filter); static List<File> listFileNameReg(File dirPath, Pattern pattern); static List<File> listFileWithHandler(File path, ObjectProcess<File, File> handler); static boolean createFile(String path); static String suffix(File file); static String fileHash(File file, String HashTyle); static String simpleEncoding(File file); static boolean zipDeCompress(File file, String zipFile); static boolean zipUnCompress(File zipFile, String path); }
FileHelper { public static boolean copy(File resource, File target) throws IOException { if (resource == null) { logger.error("copy resource is null"); return false; } if (resource.isFile()) { return copyFile(resource, target); } File[] files = resource.listFiles(); if (files == null || files.length == 0) { return target.mkdirs(); } target.mkdirs(); for (File file : files) { String targetFilePath = file.getAbsolutePath().substring(resource.getAbsolutePath().length()); File targetFile = new File(target + "/" + targetFilePath); if (file.isDirectory()) { targetFile.mkdirs(); copy(file, targetFile); } else { copyFile(file, targetFile); } } return true; }  static void handlerWithLine(File file, String encoding, ObjectHandler<String> handler); static void processWithLine(File file, String encoding, Collection<E> result, ObjectProcess<String, E> process); static int lineCounts(File file); static List<String> readLines(File file); static List<String> readLines(File file, String encoding); static String readContents(File file); final static boolean createFiles(File file); final static boolean createFiles(File file, boolean isReNew); static boolean write(File file, String str); static boolean write(File file, String str, String encoding); static boolean addWrite(File file, String str); static boolean addWrite(File file, String str, String encoding); static boolean copy(File resource, File target); static boolean copyFile(File file, File targetFile); static boolean cleanFile(File file); static boolean delete(File file); static List<File> listFile(File path); static List<File> listFileSuffix(File dirPath, String postfixs); static List<File> listFileName(File dirPath, String fileName); static List<File> listFileNameIgnoreCase(File dirPath, String fileName); static List<File> listFileFilter(File path, ObjectFilter filter); static List<File> listFileNameReg(File dirPath, Pattern pattern); static List<File> listFileWithHandler(File path, ObjectProcess<File, File> handler); static boolean createFile(String path); static String suffix(File file); static String fileHash(File file, String HashTyle); static String simpleEncoding(File file); static boolean zipDeCompress(File file, String zipFile); static boolean zipUnCompress(File zipFile, String path);  }