Your first input file doesn't have the same as the input data you have given.
If your conditions are as simple as you given in the original post, i think you are over-complicating the algorithm. I know we aren't encouraged to paste complete code but
how about something like this:
package main;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class ParseTest {
public static void main(String[] args) {
// flag to store
boolean isToBeSaved = false;
//Storage
ArrayList<String> lines = new ArrayList<String>();
//keys
String startStr = "-180.0";
String endStr = "180.0";
//Data file
String filePath = "C:\\Temp\\data.txt";
System.out.println("START OF READ LINES");
Scanner in;
try {
in = new Scanner(new File(filePath));
while ( in.hasNextLine() ) { // go trough all the lines in the data file
String line = in.nextLine();
System.out.println("\t" + line); //for debugging
if ( isToBeSaved ) { // is the line between start and end strings ( the -180 and 180 )
lines.add(line); // save the data
if ( line.contains(endStr))
isToBeSaved = false;
} else {
if ( line.contains(startStr)) {
isToBeSaved = true;
lines.add(line);
}
}
}
in.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
System.out.println("END OF READ LINES\n\n");
printStoredLines(lines);
}
//method to print out the stored data.
public static void printStoredLines(ArrayList<String> lines) {
System.out.println("START OF THE STORED LINES");
for ( String storedLine : lines )
System.out.println(storedLine);
System.out.println("END OF THE STORED LINES");
}
}