import java.io.*; import java.util.*; public class Storage { private static final String FILE_NAME = "scans.dat"; public static void saveScans(List storedScans) throws IOException { try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(FILE_NAME))) { out.writeObject(storedScans); } } @SuppressWarnings("unchecked") public static List loadScans() throws IOException, ClassNotFoundException { File file = new File(FILE_NAME); if (!file.exists()) return new ArrayList<>(); try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(FILE_NAME))) { return (List) in.readObject(); } } public static class StoredScan implements Serializable { private static final long serialVersionUID = 1L; public String type; public String accessString; public String customName; public StoredScan(String type, String accessString, String customName) { this.type = type; this.accessString = accessString; this.customName = customName; } } }