1: First copy the text in Excel into TXT and copy the following:
Table A:
ID number Work number name
310110XXXX220130004 101 Fu Jiayi
310110xxxx220130005102 Gu Yinki
310110xxxx220130006103 Guo Ga
310110xxxx220130007104 Hu Yilei
310110xxxx220130010105 Ling
310110xxxx220130011106 Lu Yanji
Table B:
ID number Work number name
310110xxxx220130004 111 Fu Jiayi
310110xxxx220130005102 Gu Yinki
310110xxxx220130006103 Guo
310110xxxx220130007104 Hu Yilei
310110xxxx220130010105 Ling
310110xxxx220130012107 Pan
2: The code and running results are as follows:
1 PackageAA;2 ImportJava.io.BufferedReader;3 ImportJava.io.File;4 ImportJava.io.FileInputStream;5 ImportJava.io.InputStreamReader;6 Importjava.util.Hashtable;7 ImportJava.util.Map.Entry;8 9 Public classDuplicateitem {Ten Public StaticHashtable<string, string>readtxtfile (String filePath) { Onehashtable<string,string> table =NewHashtable<string, string>(); A Try { -String encoding= "GBK"; -File file=NewFile (filePath); the if(File.isfile () &&file.exists ()) { -InputStreamReader Read =NewInputStreamReader ( - NewFileInputStream (file), encoding); -BufferedReader BufferedReader =NewBufferedReader (read); +String Linetxt =NULL; - while((Linetxt = Bufferedreader.readline ())! =NULL){ +String key = linetxt.substring (0, Linetxt.indexof ("\ t")); AString value = linetxt.substring (Linetxt.indexof ("\ t") +1); at Table.put (Key.trim (), Value.trim ()); - } - read.close (); -}Else{ -SYSTEM.OUT.PRINTLN ("The specified file cannot be found"); - } in}Catch(Exception e) { -SYSTEM.OUT.PRINTLN ("Error reading file contents"); to e.printstacktrace (); + } - returntable; the } * $ Public Static voidPrintall (hashtable<string,string> ht, hashtable<string, string>ht2) {Panax Notoginseng for(Entry<string, string>En:ht.entrySet ()) { - if(NULL==Ht2.get (En.getkey ())) { theSystem.out.println ("\N\TB does not have value in a" + En.getvalue (). replace ("\ T", "") + "Item \ n"); +}Else if(!en.getvalue (). Equals (Ht2.get (En.getkey ())) { ASystem.out.println ("A In value is:" + en.getvalue (). replace ("\ T", "") + "\ T with B" + Ht2.get (En.getkey ()). replace ("\ T", "") + " Different); the } + - } $ $ for(Entry<string, string>En2:ht2.entrySet ()) { - if(Ht.get (En2.getkey ()) = =NULL){ -System.out.println ("\n\ta has no value in B" + en2.getvalue (). replace ("\ T", "") + "Item \ n"); the}Else if(!en2.getvalue (). Equals (Ht.get (En2.getkey ())) { -System.out.println ("value in B" is: "+ en2.getvalue ()." Replace ("\ T", "") + "\ T with a in" + Ht.get (En2.getkey ()). replace ("\ T", "") + " Different);Wuyi } the - } Wu } - About Public Static voidMain (String argv[]) { $hashtable<string,string> table =NewHashtable<string, string>(); -hashtable<string,string> table2 =NewHashtable<string, string>(); -String FilePath = "C:\\users\\administrator\\desktop\\c.txt"; -String filePath2 = "C:\\users\\administrator\\desktop\\d.txt"; ATable =Readtxtfile (filePath); +Table2 =Readtxtfile (filePath2); the if(Table! =NULL&& table2! =NULL){ - printall (table,table2); $ } the the } the}
Use Eclipse to find the same ID number in two tables in Excel with a different name or work number