我现在有两个文本文档,我想从一个文本文档里面逐个读取词组,与第二个文本文档的所有词组比较,如果第二个文本文档不包含这个词组,则打印出来,该怎么实现?(一个词组在文本文件里是一行)

解决方案 »

  1.   

    我的代码是这样子的:
    import java.io.*;public class Compare{
     public static void main(String[] args){
      try{
       String encoding="utf-8";
       File f = new File("G://工作//a.txt");
       File f2 = new File("G://工作//b.txt");
       
       InputStreamReader read = new InputStreamReader (new FileInputStream(f),encoding);
       InputStreamReader read2 = new InputStreamReader (new FileInputStream(f2),encoding);
       BufferedReader   in   =   new   BufferedReader(read);
       BufferedReader   in2   =   new   BufferedReader(read2);
       String temp = null;
       String temp2 = null;
       while((temp = in.readLine()) != null){
      while((temp2=in2.readLine())!=null){
      if(temp.equals(temp2)!=true){

                                                   到这里该怎么写??还是我上面有错误??
                                                    
      }
      
      }
       
       }
       
       in.close();
       read.close();
       
      }catch(FileNotFoundException e){ //文件未找到
      System.out.println (e);
      }catch(IOException e){
      System.out.println (e);
      } 
     } 
    }
      

  2.   


    while((temp = in.readLine()) != null){
    while((temp2=in2.readLine())!=null){
    if(temp.equals(temp2)!=true){  System.out.println(temp2);
        
    }
      

  3.   


    while((temp = in.readLine()) != null && (temp2=in2.readLine())!= null){  if(temp.equals(temp2)!=true){    System.out.println(temp2);
     
        
      }
    }
      

  4.   

    偶终于明白了,用hashtable就简单了,你也挺辛苦的,谢谢了,分数给你了。