I'm trying to compare lines in two different files. The basic idea is I want to take line 1 of file 1 and compare it to all the lines of file 2 and print the results into a third file, then do the next line of file 1 and repeat the above steps. The problem I'm having right now is that the program reads line 1 of file 1, compares it to all the lines in file 2 (like i want it to), then it just reads the rest of the lines in file 1 without going into file 2 to compare again. For reference, pppReader is for "file 1" and seReader is for "file 2". Here is my code:
BufferedReader pppReader = new BufferedReader(new FileReader("A261r_34PPPgalaxy.cat"));
BufferedReader seReader = new BufferedReader(new FileReader("A261r_34_CLASS.cat"));
PrintWriter writer = new PrintWriter(new FileWriter("A261r_34PPPgalaxy.plot"));
String pppLine = null;
String seLine = null;
while ( (pppLine=pppReader.readLine()) != null)
{
String[] pppColumns = pppLine.split(" ");
while ((seLine=seReader.readLine()) != null)
{
String[] seColumns = seLine.split("\\s+");
float xCompare = Math.abs(Float.parseFloat(pppColumns[0]) - Float.parseFloat(seColumns[26]));
float yCompare = Math.abs(Float.parseFloat(pppColumns[1]) - Float.parseFloat(seColumns[27]));
if (xCompare <= 4000 && yCompare <= 4000)
{
float autoVsAper =
Float.parseFloat(seColumns[19]) - Float.parseFloat(seColumns[9]);
writer.println(autoVsAper + "\t" + seColumns[19]);
}
}
}
writer.close();
pppReader.close();
seReader.close();
Some System.out.println's showed me that it only goes into the second while loop the first time through, then never again. How do I fix it so it goes into file 2 everytime a line of file 1 is read