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.
I want to compare the each of the File 1 lines with all lines of the File 2 (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.
Note: I tried Danail Alexiev'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)
Files Below
File 1: Content
21321sc231231a23d1a32df1adfsdfsdfsd
fsdfs4dfs
dfsdf
3sd1f
sdfs4df3s
df0
sd4f
sdf
sdf1
3sdf
sdfs4df6s
fs1df
3sdfsd
fs.d1f
s3d1
sdf1s
df1
sdf1sdf
File 2: Content
21321sc231231a23d1a32df1adfsdfsdfsd
fsdfs4dfs
dfsdf
3sd1f
sdfs4df3s
df0
sd4f
sdf
sdf1
3sdf
sdfs4df6s
fs1df
3sdfsd
fs.d1f
s3d1
sdf1s
df1
sdf1sdf
Code:
while ((sCurrentLine1 =file1.readLine()) != null )
{
while ((sCurrentLine2 =file2.readLine()) != null )
{
if(sCurrentLine1.equalsIgnoreCase(sCurrentLine2))
{
System.out.println("=---Matched----=" + sCurrentLine1 + " -->" + sCurrentLine2);
}
else
{
System.out.println("=---Not Matched----=" + sCurrentLine1 + " -->" + sCurrentLine2);
}
}
}
O/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