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


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

comparing two test files

Started byruds <rudranee@gmail.com>
First post2011-12-23 00:45 -0800
Last post2011-12-23 07:50 -0800
Articles 9 — 5 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  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

#10966 — comparing two test files

Fromruds <rudranee@gmail.com>
Date2011-12-23 00:45 -0800
Subjectcomparing two test files
Message-ID<5fdf65a2-052b-4c0b-b6bf-bc4dc8a7dd02@v24g2000prn.googlegroups.com>
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.

[toc] | [next] | [standalone]


#10967

FromJeff Higgins <jeff@invalid.invalid>
Date2011-12-23 05:27 -0500
Message-ID<jd1kpb$edl$1@dont-email.me>
In reply to#10966
On 12/23/2011 03:45 AM, ruds wrote:
> Hi,
> Kindly help.
<http://sscce.org/>

[toc] | [prev] | [next] | [standalone]


#10968

FromJeff Higgins <jeff@invalid.invalid>
Date2011-12-23 06:03 -0500
Message-ID<jd1mtd$og8$1@dont-email.me>
In reply to#10967
On 12/23/2011 05:27 AM, Jeff Higgins wrote:
> On 12/23/2011 03:45 AM, ruds wrote:
>> Hi,
>> Kindly help.
> <http://sscce.org/>

public class Scratch {

   public static void main(String[] args) {
     while (true)
     {
       while (true)
       {
         if (true)
         {
           for (;;)
           {
             if (true) {}
           }
         }
         else {}
       }
     }
   }
}

[toc] | [prev] | [next] | [standalone]


#10973

FromPatricia Shanahan <pats@acm.org>
Date2011-12-23 06:37 -0800
Message-ID<1IGdnbzxbYSzD2nTnZ2dnUVZ_rednZ2d@earthlink.com>
In reply to#10966
On 12/23/2011 3:15 AM, Stefan Ram wrote:
> ruds<rudranee@gmail.com>  writes:
>> 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.
> (...)
>> 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.
>
>    Learn the craft of debugging: You need to inspect the values
>    of loop-critical expressions at run time and then
>    understand, why they have these values.

I've written a web page on the subject of how to debug,
http://www.patriciashanahan.com/debug

Patricia

[toc] | [prev] | [next] | [standalone]


#10976

FromGene Wirchenko <genew@ocis.net>
Date2011-12-23 09:18 -0800
Message-ID<qrd9f79atmf1cdg45spsvkls2lbvd9n1o3@4ax.com>
In reply to#10973
On Fri, 23 Dec 2011 06:37:25 -0800, Patricia Shanahan <pats@acm.org>
wrote:

[snip]

>I've written a web page on the subject of how to debug,
>http://www.patriciashanahan.com/debug

     Nice page.

     How did you come up with that example?  It is very good.  The
problem with cooking up examples like that is that one already knows
what the problem is so any "detective work" is suspect.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#10977

FromPatricia Shanahan <pats@acm.org>
Date2011-12-23 10:25 -0800
Message-ID<mf2dnTJSEL0OWmnTnZ2dnUVZ_uOdnZ2d@earthlink.com>
In reply to#10976
On 12/23/2011 9:18 AM, Gene Wirchenko wrote:
> On Fri, 23 Dec 2011 06:37:25 -0800, Patricia Shanahan<pats@acm.org>
> wrote:
>
> [snip]
>
>> I've written a web page on the subject of how to debug,
>> http://www.patriciashanahan.com/debug
>
>       Nice page.

Thanks.

>
>       How did you come up with that example?  It is very good.  The
> problem with cooking up examples like that is that one already knows
> what the problem is so any "detective work" is suspect.

I took a common student problem that needs a little attention to detail,
and wrote a Java implementation as fast as I could type, making minimal
changes to fix compile-time errors. I then went straight to test and
debug, writing up the debug steps as I went along, without doing any
desk checking.

Normally, my programming keystroke rate is a lot slower than my raw
typing rate. Suppressing self-checking and thinking about details in
favor of typing speed made a good collection of mistakes statistically
likely, but without giving me any knowledge of what the mistakes were.

I hoped the result would be a more realistic example and debug process
than if I had consciously inserted errors in an otherwise carefully
written program, and then pretended to find them.

Patricia

[toc] | [prev] | [next] | [standalone]


#10978

FromGene Wirchenko <genew@ocis.net>
Date2011-12-23 11:13 -0800
Message-ID<ffk9f7tk3br7mv804kg9frb8lrsjs2d0am@4ax.com>
In reply to#10977
On Fri, 23 Dec 2011 10:25:12 -0800, Patricia Shanahan <pats@acm.org>
wrote:

>On 12/23/2011 9:18 AM, Gene Wirchenko wrote:

[snip]

>>       How did you come up with that example?  It is very good.  The
>> problem with cooking up examples like that is that one already knows
>> what the problem is so any "detective work" is suspect.
>
>I took a common student problem that needs a little attention to detail,
>and wrote a Java implementation as fast as I could type, making minimal
>changes to fix compile-time errors. I then went straight to test and
>debug, writing up the debug steps as I went along, without doing any
>desk checking.
>
>Normally, my programming keystroke rate is a lot slower than my raw
>typing rate. Suppressing self-checking and thinking about details in
>favor of typing speed made a good collection of mistakes statistically
>likely, but without giving me any knowledge of what the mistakes were.
>
>I hoped the result would be a more realistic example and debug process
>than if I had consciously inserted errors in an otherwise carefully
>written program, and then pretended to find them.

     It is more reasonable that consciously inserting errors since you
actually did not design the errors.  You appear to have hit some good
ones, too.  That you had more than one is even better, because it
helps make the point that one should not stop after finding the first
error.

     I have bookmarked the page, and I will likely point beginners to
it.  It really is a good treatment.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#10979

FromPatricia Shanahan <pats@acm.org>
Date2011-12-23 11:45 -0800
Message-ID<R_KdnZ_TyPDWR2nTnZ2dnUVZ_rKdnZ2d@earthlink.com>
In reply to#10978
On 12/23/2011 11:13 AM, Gene Wirchenko wrote:
..
>       It is more reasonable that consciously inserting errors since you
> actually did not design the errors.  You appear to have hit some good
> ones, too.  That you had more than one is even better, because it
> helps make the point that one should not stop after finding the first
> error.

I consider that a very important point. If my first attempt had produced
only one error, I would have tried again, or tried something different,
until I did have multiple errors.

Patricia

[toc] | [prev] | [next] | [standalone]


#10974

Frommarkspace <-@.>
Date2011-12-23 07:50 -0800
Message-ID<jd27vk$l5p$1@dont-email.me>
In reply to#10966
On 12/23/2011 12:45 AM, ruds wrote:

> 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.


Besides the advice above on "how to debug," I think you need some 
practice on making the algorithm in the first place.

Try to compare two files yourself, by hand.  Write down each step as you 
do it.  Leave no detail out, no matter how small!

Then, try to write your steps as a flow chart.  Review what decisions 
you made at each step and include them on the flow chart.  It's very 
important to get these steps in something approximating an algorithm so 
you can start to understand it better.

Next pseudo code is out.  Pay attention here to basic optimization and 
"clean" code, something that looks like an algorithm. Try here to get a 
block structure pseudo code.

Then go back to the first step, where you just wrote down your steps, 
and try some new inputs.  Files with different things in them.  Make 
sure each of your steps still works.  If not, then change to so it does. 
  Check your flowchart for the same files.  Make sure the flow chart 
works.  Then check your pseudo code;  did it also work or not?

Taking the difference of two files is actually a hard problem.  You 
should expect to make a considerable effort to get it right.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web