diff --git a/src/main/java/org/example/Admin.java b/src/main/java/org/example/Admin.java index d7b4ff0..db20809 100644 --- a/src/main/java/org/example/Admin.java +++ b/src/main/java/org/example/Admin.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 administrative user in the system. @@ -60,9 +60,31 @@ public class Admin { public void writeToFile(Admin admin, String filename) throws IOException{ try(BufferedWriter writer = new BufferedWriter(new FileWriter(filename))){ - String attributes = admin.getId() + "\n" + admin.getName() + "\n" + admin.getRole(); + String attributes = admin.getName() + "\n" + admin.getId() + "\n" + admin.getRole(); writer.write(attributes); } } + public static List readFromFile(String filename) + { + List admins = 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(); + + // Read any other fields you saved + Admin admin = new Admin(name, id, role); + admins.add(admin); + } + } catch (IOException e) { + e.printStackTrace(); + } + + return admins; + } + }