标签:
package com.cici; import java.io.File; import java.io.FileInputStream; import java.util.ArrayList; import java.util.List; import org.apache.commons.io.FileUtils; public class TestCopy { private static List<File> files = new ArrayList(); public static void main(String[] args) throws Exception { TestCopy tCP = new TestCopy(); copyJars("D:\\path1", "D:\\path2"); } public static String getFilesuffix(String strs) { String ss[] = strs.split("\\.") ; return ss[1]; } public static void copyJars(String sourceDir, String destDir) throws Exception { addJarsIntoList(sourceDir); File file = new File(destDir); if (file.isDirectory()) { for (File f : files) { FileInputStream inputStream = new FileInputStream(f); FileUtils.copyFile(f, new File(file.getPath() + "\\" + f.getName())); } } } public static void addJarsIntoList(String path1) { File dir = new File(path1); if (dir.isDirectory()) { File[] subFiles = dir.listFiles(); for (File file : subFiles) //if it is file then we need to added into file list if (file.isFile()) if (getFilesuffix(file.getName()).equals("jar")) files.add(file); //if it is not file it is just directory then we need to analize it then it into directory else addJarsIntoList(file.getAbsolutePath()); } } }
标签:
原文地址:http://www.cnblogs.com/cici-new/p/4298854.html