Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #10966

comparing two test files

From ruds <rudranee@gmail.com>
Newsgroups comp.lang.java.programmer
Subject comparing two test files
Date 2011-12-23 00:45 -0800
Organization http://groups.google.com
Message-ID <5fdf65a2-052b-4c0b-b6bf-bc4dc8a7dd02@v24g2000prn.googlegroups.com> (permalink)

Show all headers | View raw


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.

Back to comp.lang.java.programmer | Previous | NextNext in thread | Find similar | Unroll thread


Thread

comparing two test files ruds <rudranee@gmail.com> - 2011-12-23 00:45 -0800
  Re: comparing two test files Jeff Higgins <jeff@invalid.invalid> - 2011-12-23 05:27 -0500
    Re: comparing two test files Jeff Higgins <jeff@invalid.invalid> - 2011-12-23 06:03 -0500
  Re: comparing two test files Patricia Shanahan <pats@acm.org> - 2011-12-23 06:37 -0800
    Re: comparing two test files Gene Wirchenko <genew@ocis.net> - 2011-12-23 09:18 -0800
      Re: comparing two test files Patricia Shanahan <pats@acm.org> - 2011-12-23 10:25 -0800
        Re: comparing two test files Gene Wirchenko <genew@ocis.net> - 2011-12-23 11:13 -0800
          Re: comparing two test files Patricia Shanahan <pats@acm.org> - 2011-12-23 11:45 -0800
  Re: comparing two test files markspace <-@.> - 2011-12-23 07:50 -0800

csiph-web