generated from hummel/Bank-System
39 lines
1.1 KiB
Java
39 lines
1.1 KiB
Java
package tpe.infrastructure;
|
|
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.ObjectInputStream;
|
|
import java.io.ObjectOutputStream;
|
|
import java.io.PrintWriter;
|
|
|
|
public class Persistenz {
|
|
private static final String Robot_DATEI = "-robot-data.ser";
|
|
|
|
public static boolean checkDataSaved(String name) {
|
|
return new File(name + Robot_DATEI).exists();
|
|
}
|
|
|
|
public static boolean deleteRobotData(String name) throws FileNotFoundException, IOException
|
|
{
|
|
File file = new File("C:\\Users\\Lukas Berens\\git\\RoboterFabrik\\"+name+"-robot-data.ser");
|
|
return file.delete();
|
|
}
|
|
|
|
public static void saveRobotData(Object robot, String name) throws Exception {
|
|
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(name + Robot_DATEI));
|
|
oos.writeObject(robot);
|
|
oos.close();
|
|
}
|
|
|
|
public static Object loadRobotData(String name) throws Exception {
|
|
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(name + Robot_DATEI));
|
|
Object robot = ois.readObject();
|
|
ois.close();
|
|
|
|
return robot;
|
|
}
|
|
|
|
} |