Click here to Skip to main content
14,332,294 members
Rate this:
Please Sign up or sign in to vote.
See more:
Text file content should like this:
1.txt : accountsservice :: 0.6.40-2ubuntu11.3 :: None :: amd64 :: None

2.txt : cronie-anacron::1.4.11::17.el7::x86_64::Friday 05 January 2018 11:13:34 
        AM 


What I have tried:

package Programm;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class StringEqual{

public static void main(String[]args){

BufferedReader in = null;
BufferedReader in2 = null;
try {
    in = new BufferedReader(new FileReader("/home/msr/Music/Ubuntu.txt"));
	in2 = new BufferedReader(new FileReader("/home/msr/Music/centos.txt"));
    
    String read = null;
    String read2 = null; 
    while ((read = in.readLine()) != null && (read2 = in2.readLine())!= null) {
        String[] splited = read.split("::");
         String[] spliter = read2.split("::");
   
    
      
   
        for (String part : splited) {
        	if(in!=in2) 
            System.out.println("packages name matches:" + part);
        }
        
        for (String part2 : spliter) {
        	if(in!=in2) 
        	System.out.println("packages not matched:" + part2);
        }
    }
}
 catch (IOException e) {
    System.out.println("There was a problem: " + e);
    e.printStackTrace();
} finally {
    try {
        in.close();
    } catch (Exception e) {
    }
}
}
}
Posted
Updated 2-May-18 22:41pm
v3
Comments
Richard MacCutchan 3-May-18 4:21am
   
What is the question?
Member 13809409 3-May-18 4:32am
   
i need to compare two text files line by line with other file all lines by two colon separate in java.
if i give package name matches it should be print what are all the package name matched with other file..this is my requirement
inside text file all lines like this:
accountsservice :: 0.6.40-2ubuntu11.3 :: None :: amd64 :: None
Richard MacCutchan 3-May-18 4:36am
   
Well that is what you already posted. But you have not explained what the problem is.
Member 13809409 3-May-18 4:58am
   
am able to compare with each line with other line only not able to compare each line with all lines with other a file
Richard MacCutchan 3-May-18 6:37am
   
Sorry, I appreciate English may not be your language, but that is still not clear. If you are trying to compare three files then you may need to do it with only two at a time. But the issue really is what you want to do when you find a line that does not match with something else. You need to make sure your rules are clear before you start.
Member 13809409 3-May-18 7:18am
   
help me with your solution ..thanks
Richard MacCutchan 3-May-18 7:43am
   
I do not have a solution, because I do not know exactly what you are trying to do.
Member 13809409 3-May-18 7:54am
   
i have two text files ie 1.txt and 2.txt separated by (::) double colon
need to compare each line of 1.txt with all lines of 2.txt if its matches i need to print matches name
thanks
sid
Richard MacCutchan 3-May-18 8:22am
   
Read both files creating lists of strings for the lines of text. Then iterate through the first set, comparing each entry with every entry in the second set. When you find a match print the result.
Member 13809409 3-May-18 8:23am
   
thanks much
Member 13809409 8-May-18 5:58am
   
hello ..iam not getting exact output of programm
Richard MacCutchan 8-May-18 11:18am
   
What does that mean?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100