找出两个文件夹下不同的文件

1. [代码][Java]代码     

01 public class NotExsitsByDir {
02 
03     private static List<String> l1 = new ArrayList<String>();
04      
05     private static List<String> l2 = new ArrayList<String>();
06 
07     /**
08      * @方法功能说明:
09      * @修改者名字: 戚羊
10      * @修改时间:2012-9-3 下午02:54:41
11      * @参数:@param args
12      * @return:void
13      */
14     public static void main(String[] args) {
15         File file = new File("F:\\test01");
16         NotExsitsByDir t = new NotExsitsByDir();
17         List<String> list1 = t.pathList(file, file ,l1);
18         File file2 = new File("D:\\新建文件夹\\test02");
19         List<String> list2 = t.pathList(file2 ,file2 ,l2);
20         List<String> h1 = new ArrayList<String>();
21         List<String> h2 = new ArrayList<String>();
22         for(String s1 : list1){
23             for(String s2 : list2){
24                 if(s1.equals(s2)){
25                     h1.add(s1);
26                     h2.add(s2);
27                 }
28             }
29         }
30         list1.removeAll(h1);
31         list2.removeAll(h2);
32         System.out.println("文件夹"+file.getName()+"有" "文件夹"+file2.getName()+"没有");
33         for(String s : list1){
34             System.out.println(s);
35         }
36         System.out.println("----------");
37         System.out.println("文件夹"+file2.getName()+"有" "文件夹"+file.getName()+"没有");
38         for(String s : list2){
39             System.out.println(s);
40         }
41     }
42 
43     /**
44      * @方法功能说明:根据文件目录得到下面所有文件的path过滤掉文件收目录 如 传入 D:\\code clean 则返回搜有此目录下的 path
45      *                                     path经过处理去除d:\\code clean这段
46      * @修改时间:2012-9-3 下午03:16:50
47      * @参数:@param file 目录文件
48      * @参数:@param fileSrc 目录文件 与 上面 file 其实是同一个file
49      * @参数:@param l1 指定一个静态list存储数据
50      * @参数:@return
51      */
52     public List<String> pathList(File file, File fileSrc ,List<String> l1) {
53         File[] list = file.listFiles();
54         if (list == null) {
55             return l1;
56         }
57         for (File f : list) {
58             if (f.isFile() && !f.isHidden()) {
59                 String path = f.getPath();
60                 String path2 = "";
61                 path2 = path.replace(fileSrc.getPath(), "");
62                 l1.add(path2);
63             else {
64                 pathList(f, fileSrc ,l1);
65             }
66         }
67         return l1;
68     }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值