|
|
@ -116,4 +116,20 @@ public class Professor { |
|
|
|
writer.newLine(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static List<Professor> readFromFile() throws IOException { |
|
|
|
List<Professor> 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; |
|
|
|
} |
|
|
|
} |