FakturierungsException Klasse + Persistenz überarbeitet
parent
8288ef6824
commit
8e8ee2e5c3
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue