import java.io.FileNotFoundException; import java.io.FileReader; import java.util.ArrayList; import java.util.Scanner; public class App { public static void main(String[] args) { ArrayList employeeList = readFile(); if (employeeList.size() > 0) { System.out.println(employeeList.get(0).name); }else { System.out.println("Nincs dolgozó"); } } public static ArrayList readFile() { ArrayList employeeList = new ArrayList<>(); try { employeeList = tryReadFile(); }catch(FileNotFoundException e) { System.err.println("Hiba! A fájl nem található!"); } return employeeList; } private static ArrayList tryReadFile() throws FileNotFoundException { ArrayList employeeList = new ArrayList<>(); FileReader fileReader = new FileReader("adat.txt"); Scanner scanner = new Scanner(fileReader); while(scanner.hasNext()) { String line = scanner.nextLine(); String[] array = line.split(":"); Employee employee = new Employee(); employee.name = array[0]; employee.city = array[1]; employeeList.add(employee); } scanner.close(); return employeeList; } }