FakturierungsException Klasse + Persistenz überarbeitet

master
BretschneiderMarvin 2023-04-15 22:38:54 +02:00
parent 8288ef6824
commit 8e8ee2e5c3
3 changed files with 43 additions and 43 deletions

View File

@ -5,9 +5,10 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Serializable;
import java.util.Scanner;
public class ConfigDatei {
public class ConfigDatei implements Serializable {
private String firmenname;
private String Firmenadresse;
@ -15,7 +16,8 @@ public class ConfigDatei {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
File tmpFile = new File("C:\\Users\\Tim\\OneDrive\\Desktop\\configu.txt");
File tmpFile = new File("C:\\Users\\Tim\\OneDrive\\Desktop\\configuration.txt");
char quote = '"';
if (!tmpFile.exists()) {
@ -43,13 +45,14 @@ public class ConfigDatei {
}
else {
//
try {
BufferedReader br = new BufferedReader(new FileReader(tmpFile));
String zeile;
while ((zeile = br.readLine()) != null) {
String werte[] = zeile.split("=");
String name = werte[0];
String value = werte[1].replace(quote, ' ').trim();
System.out.println(name + ":" + value);

View File

@ -0,0 +1,22 @@
public class FakturException extends Exception {
private int laenge;
public FakturException(String meldung) {
super(meldung);
}
public FakturException(String meldung, int laenge) {
super(meldung);
this.laenge = laenge;
}
public double getLaenge() {
return laenge;
}
}

View File

@ -1,51 +1,26 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class Persistenz {
public static final String FILEPATH = "C:\\Users\\Tim\\OneDrive\\Desktop\\c.txt";
public static final String FILEPATH = "daten.ser";
public void speichern(Datenmodell daten) throws IOException {
File file = new File(FILEPATH);
if (!file.exists()) {
file.createNewFile();
}
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
char quote = '"';
bw.write("Firmenname: " + quote + daten.getFirmenname() + quote + "\n");
bw.write("Firmenadresse: " + quote + daten.getFirmenadresse() + quote + "\n");
bw.write("Bankverbindung: " + quote + daten.getBankverbindung() + quote + "\n");
public static Datei speichereDaten(Object datei, String name) throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(name + FILEPATH));
oos.writeObject(datei);
oos.close();
return (Datei) datei;
}
public Datenmodell laden() throws IOException {
Datenmodell daten = new Datenmodell();
BufferedReader br = new BufferedReader(new FileReader(FILEPATH));
public static Object ladeDaten(String name) throws ClassNotFoundException, IOException {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(name + FILEPATH));
Object datei = ois.readObject();
ois.close();
return datei;
String zeile;
while ((zeile = br.readLine()) != null) {
String werte[] = zeile.split("=");
String name = werte[0].trim();
String value = werte[1].trim().replace("/", "");
switch (name) {
case "Firmenname":
daten.setBankverbindung(value);
break;
case "Firmenadresse":
daten.setFirmenadresse(value);
break;
case "Bankverbindung":
daten.setBankverbindung(value);
break;
}
}
br.close();
return daten;
}
}