Hi All,
I am trying to match the contents of two text files which are tab delimited. If i shift a tab to the left or right in a file or change a word or anything in one of the files, it should not match the other file. Now In the code below i need to merge the two while loops together and then i can do a check to see if the contents match, because the IF statement is not matching anything at the moment because there is nothing to match. I think a boolean method would better to check whether the contents of each file match?. Can you help me with this. Speedy reply would be very much appreciated.
try {
BufferedReader in1 = new BufferedReader(new FileReader("C:\\file1.txt"
));
BufferedReader in2 = new BufferedReader(new FileReader("C:\\file2.txt"
));
String line1;
String line2;
while ((line1 = in1.readLine()) != null) {
System.out.println("Data in file 1 is:" +line1);
}
while ((line2 = in2.readLine()) != null) {
System.out.println("\nData
in file 2 is:" +line2);
}
if(line1 == line2){
System.out.println("\nData
in file match");
}
else{
System.out.println("\nData
in file do not match");
}
}
catch (IOException e) {
e.printStackTrace();
}
Start Free Trial