1
I need to read a log saved in a TXT file that contains geographical 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 (point of the graph), separated by a comma (,).
I’m going to use these coordinates to generate a graph where each line is a point, so I need to have 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 one ArrayList
, and if that’s really the best way to do that for me to have access to that data to generate the graph afterwards.
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();
}
}
I guess it depends on the graph component you’re going to use, no?
– Sorack
"Each line has the latitude and longitude of each coordinate (point of the graph), separated by a comma (,)." - In your case, longitude is actually the first number and latitude is the second.
– Victor Stafusa
Exactly, I edited the question by fixing the error.
– BrunoPadilha