Pr_robot_factory/infrastructure/Persistenz.java

30 lines
773 B
Java
Raw Normal View History

2022-12-08 14:58:44 +01:00
package infrastructure;
2022-12-09 11:52:03 +01:00
import java.io.*;
2022-12-08 14:58:44 +01:00
public class Persistenz {
2022-12-09 11:52:03 +01:00
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){
try{
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(name + FACTORY_DATA));
oos.writeObject(Factory);
oos.close();
}catch(Exception e){
}
2022-12-09 11:52:03 +01:00
}
public static Object loadFactoryData(String name) throws Exception{
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(name + FACTORY_DATA));
Object fac = ois.readObject();
2022-12-09 11:52:03 +01:00
ois.close();
return fac;
2022-12-09 11:52:03 +01:00
}
2022-12-08 14:58:44 +01:00
}