forked from hummel/Bank-System
41 lines
1.1 KiB
Java
41 lines
1.1 KiB
Java
package persistence;
|
|
|
|
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 de.hs_mannheim.informatik.bank.domain.Bank;
|
|
|
|
public class BankSerializer {
|
|
|
|
public static void saveToFile(String filename, Bank bank) {
|
|
try(ObjectOutputStream fos = new ObjectOutputStream(new FileOutputStream(new File(filename)))) {
|
|
fos.writeObject(bank);
|
|
} catch (FileNotFoundException e) {
|
|
e.printStackTrace();
|
|
} catch (IOException e1) {
|
|
e1.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public static Bank readFromFile(String filename) {
|
|
try(ObjectInputStream fos = new ObjectInputStream(new FileInputStream(new File(filename)))) {
|
|
try {
|
|
return (Bank) fos.readObject();
|
|
} catch (ClassNotFoundException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
} catch (FileNotFoundException e) {
|
|
e.printStackTrace();
|
|
} catch (IOException e1) {
|
|
e1.printStackTrace();
|
|
}
|
|
return null;
|
|
}
|
|
}
|