diff --git a/src/main/java/org/example/Student.java b/src/main/java/org/example/Student.java index 1f2f009..5c4afe7 100644 --- a/src/main/java/org/example/Student.java +++ b/src/main/java/org/example/Student.java @@ -1,8 +1,8 @@ package org.example; -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.io.IOException; +import java.io.*; +import java.util.ArrayList; +import java.util.List; /** * Represents an student user in the system. @@ -75,5 +75,27 @@ public class Student { } + public static List readFromFile(String filename) + { + List students = new ArrayList<>(); + + try (BufferedReader reader = new BufferedReader(new FileReader(filename))) { + String line; + while ((line = reader.readLine()) != null) { + String name = line; + String id = reader.readLine(); + String role = reader.readLine(); + + Student student = new Student(name, id, role); + students.add(student); + } + } catch (IOException e) { + e.printStackTrace(); + } + + return students; + } + + }