I know the way to read the next and previous lines while reading a file line by line is like
String prev = null;
String curr = null;
String next = null;
Scanner sc = new Scanner(new File("thefile.txt"));
while(sc.hasNextLine()) {
prev = curr;
curr = next;
next = sc.nextLine();
But during the first iteration I get a null pointer exception as I have to work with the current element.
Whats the workaround for this?
Scanner sc = new Scanner(file);
String curr = null ;
String next = null ;
while (sc.hasNextLine()) {
curr = next;
next = sc.nextLine();
if(curr.length() > 0 && !curr.equals(". O O")) {
lines+= curr.substring(0, curr.indexOf(" ")) + " ";
for(String pat : patStrings)
{
// System.out.println(pat) ;
Pattern minExp = Pattern.compile (pat);
Matcher minM = minExp.matcher(curr);
while(minM.find())
{
String nerType = minM.group(2);
if(nerType.contains("B-NE_ORG")){
if (next.contains("I-NE_ORG"))
orgName+= minM.group(1)+" ";