diff --git a/src/main/java/org/example/Professor.java b/src/main/java/org/example/Professor.java index 5388030..ad7b358 100644 --- a/src/main/java/org/example/Professor.java +++ b/src/main/java/org/example/Professor.java @@ -116,4 +116,20 @@ public class Professor { writer.newLine(); } } + + public static List readFromFile() throws IOException { + List professors = new ArrayList<>(); + try (BufferedReader reader = new BufferedReader(new FileReader("professorData.txt"))) { + String line; + while ((line = reader.readLine()) != null) { + // Assuming the toString format is exactly how we write to the file + String[] parts = line.replace("Professor{", "").replace("}", "").split(", "); + String professorID = parts[0].split("'")[1]; // Extracting professorID + String name = parts[1].split("'")[1]; // Extracting Name + String role = parts[2].split("'")[1]; // Extracting role + professors.add(new Professor(professorID, name, role)); + } + } + return professors; + } }