1
0
Fork 0
WIZARD_PR2_DOP22/Infrastructure/Persistenz.java

38 lines
1.1 KiB
Java

/*
============================================================
This is the "Persistenz" file from Author: Philipp Kotte
written on: 05 / 10 / 2023 at: 23:25
============================================================
*/
package Infrastructure;
import Facade.Spiel;
import java.io.*;
public class Persistenz {
final static String FILE_NAME = "WIZARD_DATA_";
public static boolean sindDatenVorhanden(String name) {
File f = new File(FILE_NAME + name + ".ser");
if (f.exists()) {
return true;
}
return false;
}
public static void speichereDaten(String name, Spiel spiel) throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(FILE_NAME + name + ".ser"));
oos.writeObject(spiel);
oos.close();
}
public static Object ladeDaten(String name) throws IOException, ClassNotFoundException {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(FILE_NAME + name + ".ser"));
Object spiel = ois.readObject();
ois.close();
return spiel;
}
}