Persistenzklasse eingerichtet

main
Philipp3107 2022-12-09 11:52:03 +01:00
parent 697b99eb07
commit d4362b1cf4
1 changed files with 20 additions and 0 deletions

View File

@ -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;
}
}