import util.CompareFileUtil; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; public class Test { //每隔10秒打印一次,文件目录的比较结果 /** * 每隔10秒打印一次,文件目录的比较结果 * path1 path2支持传递目录,比较目录下所有文件是否内容一致。一致返回true,不一致返回false * @param args */ public static void main(String[] args) { String path1 = "D:\\data\\test1"; String path2 = "D:\\data\\test2"; TestThread testThread = new TestThread(path1, path2); testThread.start(); } static class TestThread extends Thread { private String path1; private String path2; public TestThread(String path1,String path2) { this.path1 = path1; this.path2 = path2; } @Override public void run() { while (true) { try { TimeUnit.SECONDS.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } long begin = System.currentTimeMillis(); try { CompareFileUtil.compareTo(path1,path2); } catch (Exception e) { e.printStackTrace(); } long end = System.currentTimeMillis(); System.out.println(end - begin); } } } }