From 76d0cd5683b6f6c43b9c1b39342e907727235643 Mon Sep 17 00:00:00 2001 From: informatikperson <62358979+informatikperson@users.noreply.github.com> Date: Sun, 23 Oct 2022 15:17:35 +0200 Subject: [PATCH] =?UTF-8?q?PErsisitenz=20=C3=BCbernommen=20und=20erstellt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/infrastruktur/Persistenz.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Bank-BeispielMeins/src/infrastruktur/Persistenz.java diff --git a/Bank-BeispielMeins/src/infrastruktur/Persistenz.java b/Bank-BeispielMeins/src/infrastruktur/Persistenz.java new file mode 100644 index 0000000..8282bd7 --- /dev/null +++ b/Bank-BeispielMeins/src/infrastruktur/Persistenz.java @@ -0,0 +1,33 @@ +package infrastruktur; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + +public class Persistenz { + + private static final String BANK_DATEI = "-bank-data.ser"; + + public static boolean sindDatenGespeichert(String name) { + return new File(name + BANK_DATEI).exists(); + } + + public static void speichereBankDaten(Object bank, String name) throws Exception { + ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(name + BANK_DATEI)); + oos.writeObject(bank); + oos.close(); + } + + public static Object ladeBankDaten(String name) throws Exception { + ObjectInputStream ois = new ObjectInputStream(new FileInputStream(name + BANK_DATEI)); + Object bank = ois.readObject(); + ois.close(); + + return bank; + } + + + +}