From d4362b1cf4ccb53202235fb0893b9070a29f915c Mon Sep 17 00:00:00 2001 From: Philipp3107 Date: Fri, 9 Dec 2022 11:52:03 +0100 Subject: [PATCH] Persistenzklasse eingerichtet --- infrastructure/Persistenz.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/infrastructure/Persistenz.java b/infrastructure/Persistenz.java index d33a70f..51e9b3f 100644 --- a/infrastructure/Persistenz.java +++ b/infrastructure/Persistenz.java @@ -1,4 +1,24 @@ package infrastructure; +import java.io.*; + public class Persistenz { + private static final String FACTORY_DATA = "Factory.ser"; + public static boolean existsSavedData(String name){ + return new File(name + FACTORY_DATA).exists(); + } + + public static void saveFactoryData(Object Factory, String name) throws Exception{ + ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(name + FACTORY_DATA)); + oos.writeObject(Factory); + oos.close(); + } + + public static Object loadFactoryData(String name) throws Exception{ + ObjectInputStream ois = new ObjectInputStream(new FileInputStream(name + FACTORY_DATA)); + Object Factory = ois.readObject(); + ois.close(); + return Factory; + } + }