R
ruds
Hi,
I want to compare the content of two files, which in turn gives me the
output which lines are deleted from latest version and which lines are
added in it and also if the first line no is same is details changed.
I am reading the first file line by line using BufferedReader and the
opening the second file that is the latest version in another while
loop and checking for match.
But after checking the first line, I am unable to read the second file
again and again.
Here is the code:
FileReader fin1=new FileReader(args[0]);
FileReader fin2=new FileReader(args[1]);
BufferedReader br1=new BufferedReader(fin1);
BufferedReader br2=new BufferedReader(fin2);
while((line1 = br1.readLine())!= null)
{
str1=tokens1[2].trim();
while ((line2 = br2.readLine())!= null)
{
str2=tokens2[2].trim();
if(str1.equals(str2))
{
for(j=0;j<tokens1.length;j++)
{
str3=tokens1[j].trim();
if(!(line2.contains(str3))) { //output to file that record is
changed}
}
}
else{ // str1 is not present in the file}
} //end of while for second file
} //end of while for firsts file
it iterates through the first file but doest not enter the second
while loop after reading once onle i.e for the first line of first
file.
Kindly help.
I want to compare the content of two files, which in turn gives me the
output which lines are deleted from latest version and which lines are
added in it and also if the first line no is same is details changed.
I am reading the first file line by line using BufferedReader and the
opening the second file that is the latest version in another while
loop and checking for match.
But after checking the first line, I am unable to read the second file
again and again.
Here is the code:
FileReader fin1=new FileReader(args[0]);
FileReader fin2=new FileReader(args[1]);
BufferedReader br1=new BufferedReader(fin1);
BufferedReader br2=new BufferedReader(fin2);
while((line1 = br1.readLine())!= null)
{
str1=tokens1[2].trim();
while ((line2 = br2.readLine())!= null)
{
str2=tokens2[2].trim();
if(str1.equals(str2))
{
for(j=0;j<tokens1.length;j++)
{
str3=tokens1[j].trim();
if(!(line2.contains(str3))) { //output to file that record is
changed}
}
}
else{ // str1 is not present in the file}
} //end of while for second file
} //end of while for firsts file
it iterates through the first file but doest not enter the second
while loop after reading once onle i.e for the first line of first
file.
Kindly help.