By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,103 Members | 1,121 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,103 IT Pros & Developers. It's quick & easy.

comparing two output lines.

100+
P: 281
I need help on comparing lines in my output file...
How to delete the second line in text file (FileReader) and print out the first line for the same fileno?

I put here sample of my output file:

1 : 30 at 2
1 : 134 at 10
2 : 35 at 2
4 : 30 at 2
4 : 80 at 8
..........
...........

The problem here is, not all file numbers ([0]) have same file numbers.
What I can think is something like this..but I still got the repeated fileno in my new output file.

Expand|Select|Wrap|Line Numbers
  1. lineFRST = in1.readLine(); 
  2. lineSEC = in1.readLine();      
  3.  
  4. while((lineFRST != null) && (lineSEC != null))   {    
  5. ...
  6. String[] thelineFRST = lineFRST.split(" ");
  7. String fileNo1 = thelineFRST[0];
  8.  
  9. String[] thelineSEC = lineSEC.split(" ");
  10. String fileNo2 = thelineSEC[0];
  11.  
  12. if(fileNo1.equals(fileNo2)) {
  13.                printWriter.println(lineFRST); 
  14.             }
  15.             else     {  
  16.                 printWriter.println(lineFRST); 
  17.                 printWriter.println(lineSEC); 
  18.             } 
  19.  
My new output should look like this:
1 : 30 at 2
2 : 35 at 2
4 : 30 at 2


Kindly please teach me...Thank you ....
May 15 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.