1:
bt-act-sum                  
act_id                      
cif_id                      
aum_sum                     
aum_countbt_amount
brx_id                      
org_id                      
amt_year                    
amt_month                   
amt_count                   
amt_amount 2:
bt_act_sum     
act_id
cif_id
aum_sum
aum_count
                           
bt_amount                                     
brx_id
org_id
amt_year
amt_month
amt_count
amt_amount  
amt_ccg1 和2 是个文本文件 怎么实现 1 ,2 文件的比较,把不一样的打印出来。

解决方案 »

  1.   

    你可以把两个文件分别读出来,并把每一行为一个元素放入两个数组中,然后对两个数组中的每个元素分别进行比较。
    import java.io.*;
    import java.util.*;public class CompareFile 
    {
    /**
     * 读取文件中的元素
     */
    private List readFile(String path) throws IOException {
    List array = new ArrayList();
    BufferedReader in = new BufferedReader( new FileReader(path));
    String s = new String();
    while((s = in.readLine()) != null)
    {
    array.add(s);
    }
    in.close();
    return array;
    } /**
     * 打印不同的元素
     */
    public void printNotSame(List one, List two) {
    for (int i = 0; i < two.size(); i++) {
    if (!one.contains(two.get(i))) {
    System.out.println(two.get(i));
    }
    }
    }

    public static void main(String[] args) 
    {
    CompareFile cf = new CompareFile();
    try {
    List one = cf.readFile("one.txt");
    List two = cf.readFile("two.txt");
    cf.printNotSame(one, two);
    } catch (IOException e) {
    e.printStackTrace();
    }

    }
    }
      

  2.   

    樓上正解,最好加上数组下标判断。大的作为外循环。/**
    * 打印不同的元素
    */
    public void printNotSame(List one, List two) {
    if(two.size()>one.size()){for (int i = 0; i < two.size(); i++) {
    if (!one.contains(two.get(i))) {
    System.out.println(i+":"+two.get(i));
    }
    }}
    else
    {for (int i = 0; i < one.size(); i++) {
    if (!two.contains(one.get(i))) {
    System.out.println(i+":"+one.get(i));
    }
    }}
    }