WIZARD_PR2_DOP/Infrastructure/Persistenz.java

38 lines
1.1 KiB
Java
Raw Normal View History

2023-10-05 23:32:29 +02:00
/*
============================================================
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.*;
2023-10-05 23:32:29 +02:00
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;
}
2023-10-05 23:32:29 +02:00
}