title: JAVA program for 2 or more text files comparing
body: <p>I want to compare a 2 or more Text Files to find a duplicate entry. O/P should say those lines in files are matched or not.</p>
  
  <p>I want to compare the each of the <strong>File 1</strong> lines with all lines of the <strong>File 2</strong> (ie., Comparing File 1's line-1 with all lines of File 2).
  When I run the below code the that compares the line 1 of File 1 with all lines of File 2, then program got terminated.</p>
  
  <p><strong>Note</strong>: I tried <strong>Danail Alexiev</strong>'s idea (See the answer) but the loop is running infinitely , (also not jumped to 2 line of File 1, infinite loop on File 1's line 1 with all lines of File 2)</p>
  
  <p><strong>Files Below</strong></p>
  
  <p>File  1: Content </p>
  
  <pre><code>21321sc231231a23d1a32df1adfsdfsdfsd
  fsdfs4dfs
  dfsdf
  3sd1f
  sdfs4df3s 
  df0 
  sd4f 
  sdf 
  sdf1 
  3sdf 
  sdfs4df6s 
  fs1df 
  3sdfsd 
  fs.d1f 
  s3d1
  sdf1s 
  df1 
  sdf1sdf
  </code></pre>
  
  <p>File 2: Content</p>
  
  <pre><code>21321sc231231a23d1a32df1adfsdfsdfsd
  fsdfs4dfs
  dfsdf
  3sd1f
  sdfs4df3s 
  df0 
  sd4f 
  sdf 
  sdf1 
  3sdf 
  sdfs4df6s 
  fs1df 
  3sdfsd 
  fs.d1f 
  s3d1
  sdf1s 
  df1 
  sdf1sdf
  </code></pre>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>while ((sCurrentLine1 =file1.readLine()) != null )
   {
    while ((sCurrentLine2 =file2.readLine()) != null )
     {
      if(sCurrentLine1.equalsIgnoreCase(sCurrentLine2))
       {
        System.out.println("=---Matched----=" + sCurrentLine1 + " --&gt;" + sCurrentLine2);
       }
       else
       {
        System.out.println("=---Not Matched----=" + sCurrentLine1 + " --&gt;" + sCurrentLine2);
       }
      }
    }
  </code></pre>
  
  <p><strong>O/P</strong>  :</p>
  
  <blockquote>
    <p>=---Matched----=1321sc231231a23d1a32df1adfsdfsdfsd -->1321sc231231a23d1a32df1adfsdfsdfsd
    =---Not Matched----=1321sc231231a23d1a32df1adfsdfsdfsd -->fsdfs4dfs
    =---Not Matched----=1321sc231231a23d1a32df1adfsdfsdfsd -->dfsdf
    =---Not Matched----=1321sc231231a23d1a32df1adfsdfsdfsd -->3sd1f
    =---Not Matched----=1321sc231231a23d1a32df1adfsdfsdfsd -->sdfs4df3s
    =---Not Matched----=1321sc231231a23d1a32df1adfsdfsdfsd -->df0
    =---Not Matched----=1321sc231231a23d1a32df1adfsdfsdfsd -->sd4f
    =---Not Matched----=1321sc231231a23d1a32df1adfsdfsdfsd -->sdf
    =---Not Matched----=1321sc231231a23d1a32df1adfsdfsdfsd -->sdf1
    =---Not Matched----=1321sc231231a23d1a32df1adfsdfsdfsd -->3sdf
    =---Not Matched----=1321sc231231a23d1a32df1adfsdfsdfsd -->sdfs4df6s
    =---Not Matched----=1321sc231231a23d1a32df1adfsdfsdfsd -->fs1df
    =---Not Matched----=1321sc231231a23d1a32df1adfsdfsdfsd -->3sdfsd
    =---Not Matched----=1321sc231231a23d1a32df1adfsdfsdfsd -->fs.d1f
    =---Not Matched----=1321sc231231a23d1a32df1adfsdfsdfsd -->s3d1
    =---Not Matched----=1321sc231231a23d1a32df1adfsdfsdfsd -->sdf1s
    =---Not Matched----=1321sc231231a23d1a32df1adfsdfsdfsd -->df1
    =---Not Matched----=1321sc231231a23d1a32df1adfsdfsdfsd -->sdf1sdf</p>
  </blockquote>