I need to read a log recorded in a TXT file that contains geographic coordinates in the following form:
-54.123440,-21.123456
-54.123425,-21.123467
-54.123435,-21.123480
-54.123444,-21.123444
-54.123452,-21.123100
Each line has the longitude and latitude of each coordinate (plot point), separated by a comma (,).
I will use these coordinates to generate a graph where each line is a point, so I need access to the latitude and longitude of each point. I would like to know how to store the latitude and longitude of each point in a ArrayList
, and if this is really the best way to do it so I have access to that data to generate the graph later.
I can read the file and print line by line, through the following class:
public class Leitura {
public void leTXT() {
Scanner ler = new Scanner(System.in);
try {
FileReader arq = new FileReader("c:/dados/log.txt");
BufferedReader lerArq = new BufferedReader(arq);
String str = lerArq.readLine();
while (str != null) {
System.out.printf("%s\n", str);
str = lerArq.readLine();
}
arq.close();
} catch (IOException e) {
System.err.printf("Erro na abertura do arquivo!");
}
System.out.println();
}
}