I'm trying to compare two files line by line. Let's say for example:
File1
a,b,c,d,12
e,f,g,h,20
h,g,t,y,30
File2
f,g,h,j,30
e,h,j,f,50
a,b,c,d,60
e,f,g,h,70
I want my output to be like:
a,b,c,d,12,50
e,f,g,h,20,70
I've written this code:
while ((line1 = bufferedFormattedReaderMaster.readLine()) != null) {
temp1 = line1.substring(0, 7);
temp3 = line1.substring(8, 10);
while ((line2 = bufferedFormattedReaderAnalytical.readLine()) != null) {
temp2 = line2.substring(0, 7);
temp4 = line2.substring(8, 10);
if (temp1.equals(temp2)) {
System.out.println("OH YES");
bufferedWriterFinalResults.write(temp1 + "," +temp3 + "," + temp4);
bufferedWriterFinalResults.newLine();
numberOfFinalResults++;
}
}
}
But my output is only:
a,b,c,d,12,50
and not the next line.