import java.io.File; import java.util.Arrays; public class CompareFileDirector { // // D:\soft\Java\jdk_1.8.0.0_64\bin\javapackager.exe false // D:\soft\Java\jdk_1.8.0.0_64\bin\jdeps.exe false // D:\soft\Java\jdk_1.8.0.0_64\bin\jjs.exe false // D:\soft\Java\jdk_1.8.0.0_64\javafx-src.zip false // D:\soft\Java\jdk_1.8.0.0_64\jre\bin\decora_sse.dll false // D:\soft\Java\jdk_1.8.0.0_64\jre\bin\j2pkcs11.dll false // D:\soft\Java\jdk_1.8.0.0_64\jre\bin\javafx_font.dll false // D:\soft\Java\jdk_1.8.0.0_64\jre\bin\javafx_font_t2k.dll false // D:\soft\Java\jdk_1.8.0.0_64\jre\bin\javafx_iio.dll false // D:\soft\Java\jdk_1.8.0.0_64\jre\bin\jjs.exe false // D:\soft\Java\jdk_1.8.0.0_64\jre\bin\lcms.dll false // D:\soft\Java\jdk_1.8.0.0_64\jre\bin\prism_common.dll false // D:\soft\Java\jdk_1.8.0.0_64\jre\bin\prism_d3d.dll false // D:\soft\Java\jdk_1.8.0.0_64\jre\bin\prism_es2.dll false // D:\soft\Java\jdk_1.8.0.0_64\jre\bin\prism_sw.dll false // D:\soft\Java\jdk_1.8.0.0_64\jre\lib\ext\cldrdata.jar false // D:\soft\Java\jdk_1.8.0.0_64\jre\lib\ext\jfxrt.jar false // D:\soft\Java\jdk_1.8.0.0_64\jre\lib\ext\nashorn.jar false // D:\soft\Java\jdk_1.8.0.0_64\jre\lib\ext\sunpkcs11.jar false // D:\soft\Java\jdk_1.8.0.0_64\jre\lib\hijrah-config-umalqura.properties false // D:\soft\Java\jdk_1.8.0.0_64\jre\lib\jfxswt.jar false // D:\soft\Java\jdk_1.8.0.0_64\jre\lib\security\blacklisted.certs false // D:\soft\Java\jdk_1.8.0.0_64\jre\lib\tzdb.dat false // D:\soft\Java\jdk_1.8.0.0_64\jre.exe false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\config\Modules\org-netbeans-core-multitabs.xml false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\config\Modules\org-netbeans-lib-uihandler.xml false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\config\Modules\org-netbeans-modules-keyring-fallback.xml false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\config\Modules\org-netbeans-modules-uihandler.xml false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\modules\locale\org-netbeans-core-multitabs_ja.jar false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\modules\locale\org-netbeans-core-multitabs_zh_CN.jar false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\modules\locale\org-netbeans-core-network_ja.jar false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\modules\locale\org-netbeans-core-network_zh_CN.jar false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\modules\locale\org-netbeans-lib-uihandler_ja.jar false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\modules\locale\org-netbeans-lib-uihandler_zh_CN.jar false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\modules\locale\org-netbeans-modules-keyring-fallback_ja.jar false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\modules\locale\org-netbeans-modules-keyring-fallback_zh_CN.jar false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\modules\locale\org-netbeans-modules-uihandler_ja.jar false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\modules\locale\org-netbeans-modules-uihandler_zh_CN.jar false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\modules\org-netbeans-core-multitabs.jar false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\modules\org-netbeans-lib-uihandler.jar false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\modules\org-netbeans-modules-keyring-fallback.jar false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\modules\org-netbeans-modules-uihandler.jar false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\\update_tracking\org-netbeans-core-multitabs.xml false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\\update_tracking\org-netbeans-lib-uihandler.xml false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\\update_tracking\org-netbeans-modules-keyring-fallback.xml false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\platform\\update_tracking\org-netbeans-modules-uihandler.xml false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\visualvm\config\Modules\org-netbeans-lib-uihandler.xml_hidden false // D:\soft\Java\jdk_1.8.0.0_64\lib\visualvm\visualvm\config\Modules\org-netbeans-modules-uihandler.xml_hidden false // ========= // D:\soft\Java\jdk1.7.0_72\bin\apt.exe false // D:\soft\Java\jdk1.7.0_72\jre\bin\decora-sse.dll false // D:\soft\Java\jdk1.7.0_72\jre\bin\javafx-font.dll false // D:\soft\Java\jdk1.7.0_72\jre\bin\javafx-iio.dll false // D:\soft\Java\jdk1.7.0_72\jre\bin\JdbcOdbc.dll false // D:\soft\Java\jdk1.7.0_72\jre\bin\libxml2.dll false // D:\soft\Java\jdk1.7.0_72\jre\bin\libxslt.dll false // D:\soft\Java\jdk1.7.0_72\jre\bin\prism-d3d.dll false // D:\soft\Java\jdk1.7.0_72\jre\lib\alt-rt.jar false // D:\soft\Java\jdk1.7.0_72\jre\lib\jfxrt.jar false // D:\soft\Java\jdk1.7.0_72\jre\lib\launcher.exe false // D:\soft\Java\jdk1.7.0_72\jre\lib\security\javafx.policy false // D:\soft\Java\jdk1.7.0_72\jre\lib\Africa false // D:\soft\Java\jdk1.7.0_72\jre\lib\America false // D:\soft\Java\jdk1.7.0_72\jre\lib\Antarctica false // D:\soft\Java\jdk1.7.0_72\jre\lib\Asia false // D:\soft\Java\jdk1.7.0_72\jre\lib\Atlantic false // D:\soft\Java\jdk1.7.0_72\jre\lib\Australia false // D:\soft\Java\jdk1.7.0_72\jre\lib\CET false // D:\soft\Java\jdk1.7.0_72\jre\lib\CST6CDT false // D:\soft\Java\jdk1.7.0_72\jre\lib\EET false // D:\soft\Java\jdk1.7.0_72\jre\lib\EST false // D:\soft\Java\jdk1.7.0_72\jre\lib\EST5EDT false // D:\soft\Java\jdk1.7.0_72\jre\lib\Etc false // D:\soft\Java\jdk1.7.0_72\jre\lib\Europe false // D:\soft\Java\jdk1.7.0_72\jre\lib\GMT false // D:\soft\Java\jdk1.7.0_72\jre\lib\HST false // D:\soft\Java\jdk1.7.0_72\jre\lib\Indian false // D:\soft\Java\jdk1.7.0_72\jre\lib\MET false // D:\soft\Java\jdk1.7.0_72\jre\lib\MST false // D:\soft\Java\jdk1.7.0_72\jre\lib\MST7MDT false // D:\soft\Java\jdk1.7.0_72\jre\lib\Pacific false // D:\soft\Java\jdk1.7.0_72\jre\lib\PST8PDT false // D:\soft\Java\jdk1.7.0_72\jre\lib\SystemV false // D:\soft\Java\jdk1.7.0_72\jre\lib\WET false // D:\soft\Java\jdk1.7.0_72\jre\lib\ZoneInfoMappings false // D:\soft\Java\jdk1.7.0_72\lib\javafx-doclet.jar false // D:\soft\Java\jdk1.7.0_72\lib\visualvm\platform\modules\ext\nsProxyAutoConfig.js false public static void main(String[] args) { String target1Path = "D:\\soft\\Java\\jdk_1.8.0.0_64"; String target2Path = "D:\\soft\\Java\\jdk1.7.0_72"; compareFileDorector( target1Path, target2Path); compareFileDorector( target2Path, target1Path); } /** * * 左边 多的 + * 左边少的 - * */ private static void compareFileDorector( String target1Path,String target2Path) { if( new File(target1Path).isDirectory()){ String[] target1PathList = new File(target1Path).list(); String[] target2PathList = new File(target2Path).list(); for (int i = 0; i < target1PathList.length; i++) { String target1FileName = target1PathList[i]; boolean target1FileExits= Arrays.asList(target2PathList).contains(target1FileName); boolean target1FileIsDirectory = new File(target1Path,target1FileName).isDirectory(); if ( target1FileExits ) { boolean target2FileIsDirectory = new File(target2Path,target1FileName).isDirectory(); boolean isSameDirectory = target1FileIsDirectory ^ target2FileIsDirectory; if (isSameDirectory) { //文件存在,并且 文件类型不同 printInfo(target1Path,target2Path,target1FileName,target1FileExits,target1FileIsDirectory,target2FileIsDirectory); }else{ //文件存在,并且 文件类型相同 compareFileDorector( new File(target1Path,target1FileName).getAbsolutePath(), new File(target2Path,target1FileName).getAbsolutePath()); } }else { //文件夹不存在,并且 文件一 是 文件夹 printInfo(target1Path,target2Path,target1FileName,target1FileExits,target1FileIsDirectory,false); } } } } //1.0文件存在并且文件类型不同,才会打印, //1.1 文件不存在,类型是文件夹,循环打印 //1.2 文件不存在,类型是文件,打印一次 private static void printInfo(String target1Path, String target2Path,String target1FileName, boolean target1FileExits, boolean target1FileIsDirectory, boolean target2FileIsDirectory) { if (target1FileExits) { File file1 = new File(target1Path,target1FileName); File file2 = new File(target2Path,target1FileName); String absolutePath1 = file1.getAbsolutePath(); String absolutePath2 = file2.getAbsolutePath(); System.out.println(absolutePath1 +"\t" +target1FileIsDirectory +"\t"+absolutePath2+"\t"+target2FileIsDirectory); return; }else if(target1FileIsDirectory){ File file1 = new File(target1Path,target1FileName); if(file1.isDirectory()){ String[] target1PathList= file1.list(); for (int i = 0; i < target1PathList.length; i++) { String target1FileName1 = target1PathList[i]; String target1Path1 = new File(target1Path,target1FileName1).getAbsolutePath(); boolean target1FileIsDirectory1 = new File(target1Path,target1FileName1).isDirectory(); printInfo(target1Path,"",target1FileName1,false,target1FileIsDirectory1,false); } }else{ return; } }else{ File file1 = new File(target1Path,target1FileName); String absolutePath1 = file1.getAbsolutePath(); System.out.println(absolutePath1 +"\t" +target1FileIsDirectory +"\t \t "); return; } } }
捐助开发者
在兴趣的驱动下,写一个免费
的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(支持支付宝和微信 以及扣扣群),没钱捧个人场,谢谢各位。
个人主页:http://knight-black-bob.iteye.com/
谢谢您的赞助,我会做的更好!