FakturierungsException Klasse + Persistenz überarbeitet
parent
8288ef6824
commit
8e8ee2e5c3
|
@ -5,9 +5,10 @@ import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class ConfigDatei {
|
public class ConfigDatei implements Serializable {
|
||||||
|
|
||||||
private String firmenname;
|
private String firmenname;
|
||||||
private String Firmenadresse;
|
private String Firmenadresse;
|
||||||
|
@ -15,7 +16,8 @@ public class ConfigDatei {
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
Scanner sc = new Scanner(System.in);
|
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 = '"';
|
char quote = '"';
|
||||||
|
|
||||||
if (!tmpFile.exists()) {
|
if (!tmpFile.exists()) {
|
||||||
|
@ -43,13 +45,14 @@ public class ConfigDatei {
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
//
|
|
||||||
try {
|
try {
|
||||||
BufferedReader br = new BufferedReader(new FileReader(tmpFile));
|
BufferedReader br = new BufferedReader(new FileReader(tmpFile));
|
||||||
String zeile;
|
String zeile;
|
||||||
while ((zeile = br.readLine()) != null) {
|
while ((zeile = br.readLine()) != null) {
|
||||||
String werte[] = zeile.split("=");
|
String werte[] = zeile.split("=");
|
||||||
String name = werte[0];
|
String name = werte[0];
|
||||||
|
|
||||||
String value = werte[1].replace(quote, ' ').trim();
|
String value = werte[1].replace(quote, ' ').trim();
|
||||||
System.out.println(name + ":" + value);
|
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.FileInputStream;
|
||||||
import java.io.BufferedWriter;
|
import java.io.FileOutputStream;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
|
||||||
public class Persistenz {
|
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 {
|
public static Datei speichereDaten(Object datei, String name) throws IOException {
|
||||||
File file = new File(FILEPATH);
|
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(name + FILEPATH));
|
||||||
if (!file.exists()) {
|
oos.writeObject(datei);
|
||||||
file.createNewFile();
|
oos.close();
|
||||||
}
|
return (Datei) datei;
|
||||||
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 Datenmodell laden() throws IOException {
|
public static Object ladeDaten(String name) throws ClassNotFoundException, IOException {
|
||||||
Datenmodell daten = new Datenmodell();
|
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(name + FILEPATH));
|
||||||
BufferedReader br = new BufferedReader(new FileReader(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