I have a txt file like this which contains longitude and latitude coords:
120.12 22.233
100 23.12
98 19.12
If I want to read the file, I am doing:
List<String> lines = Files.readAllLines(Paths.get(fileName));
System.out.println("LINE: " + lines.get(0));
and it gives me : 120 22
I have a class that reads latitude and longitude:
public class GisPoints {
private double lat;
private double lon;
public GisPoints() {
}
public GisPoints(double lat, double lon) {
super();
this.lat = lat;
this.lon = lon;
}
//Getters and Setters
}
I want to store all the values from the txt file into an List<GisPoints>.
So, I want a function in order to load file:
public static List<GisPoints> loadData(String fileName) throws IOException {
List<String> lines = Files.readAllLines(Paths.get(fileName));
List<GisPoints> points = new ArrayList<GisPoints>();
//for (int i = 0; i < lines.size(); i++) {
// }
return points;
}
As I said, right now I am just reading every line, for example lines[0] = 120 22
I want to store lines[0] longitude into points[0].setLon(), lines[0] latitude into points[0].setLat().