public static ArrayList<Distinct> readFromFile(String file) throws Exception { BufferedReader br = new BufferedReader(new FileReader(file)); ArrayList<Distinct> distincts = new ArrayList<Distinct>(); try { String line = br.readLine(); while (line != null) { String[] array = line.split(","); if (array.length == 5) { try { Distinct distinct = new Distinct(); distinct.setName(array[2].trim()); distinct.setLatitudeAsDouble(Double.parseDouble(array[3].trim())); distinct.setLongitudeAsDouble(Double.parseDouble(array[4].trim())); distincts.add(distinct); } catch (Exception e) { e.printStackTrace(); } } line = br.readLine(); } return distincts; } finally { br.close(); } }
/** @param args */ public static void main(String[] args) throws Exception { ArrayList<Distinct> distincts = readFromFile("C:\\Users\\EXT0173773\\workspace3\\FoursquareTest\\resources\\coordinates2"); for (Distinct distinct : distincts) { System.out.println( distinct.getName() + "\t" + distinct.getLatitudeAsDouble() + "\t" + distinct.getLongitudeAsDouble()); } }