标签:
import java.io.File; import java.util.ArrayList; import java.util.List; public class FileReader { static List<String> result = new ArrayList<String>(); static String path1 = "D:\\commit\\HAManager\\0807"; static String path2 = "D:\\commit\\HAManager\\0811"; public static void main(String[] args) { File file = new File(path1); File[] tempList = file.listFiles(); for (int i = 0; i < tempList.length; i++) { comeOn(tempList[i], path1); } File file2 = new File(path2); File[] tempList2 = file2.listFiles(); for (int i = 0; i < tempList2.length; i++) { comeOn(tempList2[i], path2); } for (String fileName : result) { System.out.println(fileName); } } private static void comeOn(File file, String path) { if (file.isFile()) { if (file.getName().endsWith(".js")) { String jsFile = file.toString().replace(path, "").replace("\\", "/"); if (!result.contains(jsFile)) { result.add(jsFile); } } else if (file.getName().endsWith(".class")) { String javaFile = file.toString().replace(path, "").replace("classes", "").replace("class", "java").replace("\\", "/").replace("//", "/"); if (!result.contains(javaFile)) { result.add(javaFile); } } else if (file.getName().endsWith(".jsp")) { String jspFile = file.toString().replace(path, "").replace("\\", "/"); if (!result.contains(jspFile)) { result.add(jspFile); } } else if (file.getName().endsWith(".xml")) { String xmlFile = file.toString().replace(path, "").replace("\\", "/").replace("//", "/"); if (!result.contains(xmlFile)) { result.add(xmlFile); } } else if (file.getName().endsWith(".css")){ String cssFile = file.toString().replace(path, "").replace("\\", "/").replace("//", "/"); if (!result.contains(cssFile)) { result.add(cssFile); } } else { if (!result.contains(file.toString())) { result.add(file.toString()); } } } if (file.isDirectory()) { File[] tempList = file.listFiles(); for (int i = 0; i < tempList.length; i++) { comeOn(tempList[i], path); } } } }
标签:
原文地址:http://www.cnblogs.com/voctrals/p/4723702.html