Hello forum,
I am stuck with a field comparison problem for two files. In one file I have first names and other pet names. Now I am trying to get results where first names are within a 20 word range of pet names(+-20 for checking on each side of word boundary of pet name). First name file has 5 columns and pet name file has 3 columns. All columns are tab separated. The third column of firstnamefile.txt has the beginning index of first names. The second column of petnamefile.txt has the beginning index of pet names. I am trying to compare these to get the word range mentioned above for the entire coulms of two files.
Here goes my code:
import java.io.*;
public class NameAssc {
public static void main(String[] args) throws FileNotFoundException, IOException {
BufferedReader fn = new BufferedReader(new FileReader("firstnamefile.txt"));
BufferedReader pn = new BufferedReader(new FileReader("petnamefile.txt"));
String s1;
String s2;
while (((s1=fn.readLine())!=null))
{
String arr1[] = s1.split("\t");
int fstart = Integer.parseInt(arr1[2]);
while(((s2=pn.readLine())!=null))
{
String arr2[] = s2.split("\t");
int pstart = Integer.parseInt(arr2[1]);
if((fstart>pstart-20)&&(fstart<pstart+20))
{
System.out.println(fstart+"\t"+pstart);
}
}
}
fn.close();
pn.close();
}
}
the problem is that the code returns correct values in the first iteration, but from the second iteration it does not enter the inner while loop.(tested it with print statements). Any help is appreciated. Please let me know if you have any questions about the problem.