From 1bd9bb761ad0ebb7a1c6d08dceea89d806b61632 Mon Sep 17 00:00:00 2001 From: Gerd Marmitt Date: Wed, 3 Apr 2024 10:46:59 +0200 Subject: [PATCH] initial example files regarding i/o --- DemoAnonymeKlasse/.DS_Store | Bin 0 -> 6148 bytes DemoAnonymeKlasse/.vscode/settings.json | 7 +++ DemoAnonymeKlasse/README.md | 18 +++++++ DemoAnonymeKlasse/bin/.DS_Store | Bin 0 -> 6148 bytes DemoAnonymeKlasse/src/.DS_Store | Bin 0 -> 6148 bytes DemoAnonymeKlasse/src/BerechnungDouble.java | 8 +++ DemoAnonymeKlasse/src/DemoAnonymeKlasse.java | 23 ++++++++ DemoXMLSerialisierung/.vscode/settings.json | 7 +++ DemoXMLSerialisierung/README.md | 18 +++++++ DemoXMLSerialisierung/src/Beispiel.xml | 14 +++++ .../src/DemoXMLSerialisierung.java | 46 ++++++++++++++++ DemoXMLSerialisierung/src/Person.java | 50 ++++++++++++++++++ Eingabe/.vscode/settings.json | 7 +++ Eingabe/README.md | 18 +++++++ Eingabe/src/Eingabe.java | 30 +++++++++++ Eingabe_BufferedReader/.vscode/settings.json | 7 +++ Eingabe_BufferedReader/README.md | 18 +++++++ .../src/Eingabe_BufferedReader.java | 17 ++++++ Eingabe_Scanner/.vscode/settings.json | 7 +++ Eingabe_Scanner/README.md | 18 +++++++ Eingabe_Scanner/src/Eingabe_Scanner.java | 17 ++++++ LeseDatei/.DS_Store | Bin 0 -> 6148 bytes LeseDatei/.vscode/settings.json | 7 +++ LeseDatei/README.md | 18 +++++++ LeseDatei/src/LeseDatei.java | 40 ++++++++++++++ LeseDatei2/.vscode/settings.json | 7 +++ LeseDatei2/README.md | 18 +++++++ LeseDatei2/src/LeseDatei2.java | 26 +++++++++ LeseDateiGepuffert/.vscode/settings.json | 7 +++ LeseDateiGepuffert/README.md | 18 +++++++ .../src/LeseDateiGepuffert.java | 29 ++++++++++ LeseDateiMitZeilennr/.vscode/settings.json | 7 +++ LeseDateiMitZeilennr/README.md | 18 +++++++ .../src/LeseDateiMitZeilennr.java | 26 +++++++++ Roemisch/.vscode/settings.json | 7 +++ Roemisch/README.md | 18 +++++++ Roemisch/src/Roemisch.java | 24 +++++++++ SchreibeDatei/.vscode/settings.json | 7 +++ SchreibeDatei/README.md | 18 +++++++ SchreibeDatei/src/SchreibeDatei.java | 26 +++++++++ SchreibeDatei/src/Schreibedatei.txt | 2 + .../.vscode/settings.json | 7 +++ SchreibeDateiMitPrintWriter/README.md | 18 +++++++ .../src/MesswerteDatei.txt | 2 + .../src/SchreibeDateiMitPrintWriter.java | 23 ++++++++ 45 files changed, 703 insertions(+) create mode 100644 DemoAnonymeKlasse/.DS_Store create mode 100644 DemoAnonymeKlasse/.vscode/settings.json create mode 100644 DemoAnonymeKlasse/README.md create mode 100644 DemoAnonymeKlasse/bin/.DS_Store create mode 100644 DemoAnonymeKlasse/src/.DS_Store create mode 100644 DemoAnonymeKlasse/src/BerechnungDouble.java create mode 100644 DemoAnonymeKlasse/src/DemoAnonymeKlasse.java create mode 100644 DemoXMLSerialisierung/.vscode/settings.json create mode 100644 DemoXMLSerialisierung/README.md create mode 100644 DemoXMLSerialisierung/src/Beispiel.xml create mode 100644 DemoXMLSerialisierung/src/DemoXMLSerialisierung.java create mode 100644 DemoXMLSerialisierung/src/Person.java create mode 100644 Eingabe/.vscode/settings.json create mode 100644 Eingabe/README.md create mode 100644 Eingabe/src/Eingabe.java create mode 100644 Eingabe_BufferedReader/.vscode/settings.json create mode 100644 Eingabe_BufferedReader/README.md create mode 100644 Eingabe_BufferedReader/src/Eingabe_BufferedReader.java create mode 100644 Eingabe_Scanner/.vscode/settings.json create mode 100644 Eingabe_Scanner/README.md create mode 100644 Eingabe_Scanner/src/Eingabe_Scanner.java create mode 100644 LeseDatei/.DS_Store create mode 100644 LeseDatei/.vscode/settings.json create mode 100644 LeseDatei/README.md create mode 100644 LeseDatei/src/LeseDatei.java create mode 100644 LeseDatei2/.vscode/settings.json create mode 100644 LeseDatei2/README.md create mode 100644 LeseDatei2/src/LeseDatei2.java create mode 100644 LeseDateiGepuffert/.vscode/settings.json create mode 100644 LeseDateiGepuffert/README.md create mode 100644 LeseDateiGepuffert/src/LeseDateiGepuffert.java create mode 100644 LeseDateiMitZeilennr/.vscode/settings.json create mode 100644 LeseDateiMitZeilennr/README.md create mode 100644 LeseDateiMitZeilennr/src/LeseDateiMitZeilennr.java create mode 100644 Roemisch/.vscode/settings.json create mode 100644 Roemisch/README.md create mode 100644 Roemisch/src/Roemisch.java create mode 100644 SchreibeDatei/.vscode/settings.json create mode 100644 SchreibeDatei/README.md create mode 100644 SchreibeDatei/src/SchreibeDatei.java create mode 100644 SchreibeDatei/src/Schreibedatei.txt create mode 100644 SchreibeDateiMitPrintWriter/.vscode/settings.json create mode 100644 SchreibeDateiMitPrintWriter/README.md create mode 100644 SchreibeDateiMitPrintWriter/src/MesswerteDatei.txt create mode 100644 SchreibeDateiMitPrintWriter/src/SchreibeDateiMitPrintWriter.java diff --git a/DemoAnonymeKlasse/.DS_Store b/DemoAnonymeKlasse/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0635bac0bae8b567ba86a6291db267f0977d5e45 GIT binary patch literal 6148 zcmeHKO>f#j5S_&|u@zO~kSMuSveYZ0q(z7*7l)8T4!y)tduS_)F>0+CZ-gNn5R$J+ ze@u?~C;2<=+YcfE=`oe4W~AA-JNss>eTH2R5sCIBJ|wCTkqcK?^3XhEYF_!8m26}S zDAXFVAEh$FNG-><2@0rp=TJlmW#{SA`#Zr*?YB0)5rPnh&L-44&^kW{tD~Y^Q>r^U)$fNmkFt7TvR-;+<8?D3n+;jKdzB|6?UZulK-fFQ(;18kgwZ#S8p<}mv6OOV} zWDZLJ_v~5Wc392n=$| z3a|pp3OHt1QTPAZ-|PS7Bp$H>tiXSzfGBsuP8(aYck9~b)LrYtzr&R&USaSl1s#1A ggR8FM1GqNCeboU577K%j!1zNz%fJmQ@J|)^0~z~uVE_OC literal 0 HcmV?d00001 diff --git a/DemoAnonymeKlasse/.vscode/settings.json b/DemoAnonymeKlasse/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/DemoAnonymeKlasse/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/DemoAnonymeKlasse/README.md b/DemoAnonymeKlasse/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/DemoAnonymeKlasse/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/DemoAnonymeKlasse/bin/.DS_Store b/DemoAnonymeKlasse/bin/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9e263d7c86195387ef3e7da6c5f0f3e99fff998d GIT binary patch literal 6148 zcmeHK%Sr?>5Ul7P7QF05@gn347W{)aj0f@P4>+?f$}&2jtl(|_$WPR&bQDL&n}|sF z(y30TyE7@+JOG4hdvy#f0L-bvAY(%0o*ddK!NQPhtZ;)nY^m21h5n*T-@cCuYur;m zet(UgD{0Zuzr+R&9?_h2{i^NymRX|gnYw(*LJK%R&FEWZo{)o{`o!KE=d9A;fxmBS zg`-ckazSsL0cXG&a0Z-#A7_APwq(9%=&dv03^)Vt3}}CdRADMO80M{mjjqocp9v+j zbukvkf~nwO$Pr4gRHCJZ^27+1PJb+Mso-E}=?Hmd)+sZ;Jzhedo&K1^5t5;|&VVy8 zW?fBj e!#rr?Q8wdJ!NE{f5Ul7P7QF05@gn347W{)aj0f@P4>+?f$}&2jtl(|_$WPR&bQDL&n}|sF z(y30TyE7@+JOG4hdvy#f0L-bvAY(%0o*ddK!NQPhtZ;)nY^m21h5n*T-@cCuYur;m zet(UgD{0Zuzr+R&9?_h2{i^NymRX|gnYw(*LJK%R&FEWZo{)o{`o!KE=d9A;fxmBS zg`-ckazSsL0cXG&a0Z-#A7_APwq(9%=&dv03^)Vt3}}CdRADMO80M{mjjqocp9v+j zbukvkf~nwO$Pr4gRHCJZ^27+1PJb+Mso-E}=?Hmd)+sZ;Jzhedo&K1^5t5;|&VVy8 zW?fBj e!#rr?Q8wdJ!NE{f " + methode.berechne(x)); + } + } + + public static void main(String[] args) { + druckeTabelle( + new BerechnungDouble() { + public double berechne(double wert) { + return Math.sqrt(wert); + } + }); + } +} diff --git a/DemoXMLSerialisierung/.vscode/settings.json b/DemoXMLSerialisierung/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/DemoXMLSerialisierung/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/DemoXMLSerialisierung/README.md b/DemoXMLSerialisierung/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/DemoXMLSerialisierung/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/DemoXMLSerialisierung/src/Beispiel.xml b/DemoXMLSerialisierung/src/Beispiel.xml new file mode 100644 index 0000000..c77f389 --- /dev/null +++ b/DemoXMLSerialisierung/src/Beispiel.xml @@ -0,0 +1,14 @@ + + + + + 38 + + + Mustermann + + + Harald + + + diff --git a/DemoXMLSerialisierung/src/DemoXMLSerialisierung.java b/DemoXMLSerialisierung/src/DemoXMLSerialisierung.java new file mode 100644 index 0000000..f0ab169 --- /dev/null +++ b/DemoXMLSerialisierung/src/DemoXMLSerialisierung.java @@ -0,0 +1,46 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * XML-Serialisierung von Objekten, S. 273 f. +*/ + +import java.io.*; +import java.beans.*; + +public class DemoXMLSerialisierung { + + public static void main(String[] args) { + Person einePerson = + new Person("Mustermann", + "Harald", 38); + String filename = "DemoXMLSerialisierung/src/Beispiel.xml"; + + // Serialisieren + + try(XMLEncoder enc = + new XMLEncoder( + new FileOutputStream(filename))) + { + enc.writeObject(einePerson); + } + catch(IOException e) + { + e.printStackTrace(); + } + + // Deserialisieren + try(XMLDecoder dec = + new XMLDecoder( + new FileInputStream(filename))) + { + Person wiedereinePerson = + (Person) dec.readObject(); + System.out.println(wiedereinePerson.getName() + ", " + + wiedereinePerson.getVorname() + ", Alter: " + + wiedereinePerson.getAlter()); + } + catch(IOException e) + { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/DemoXMLSerialisierung/src/Person.java b/DemoXMLSerialisierung/src/Person.java new file mode 100644 index 0000000..510064d --- /dev/null +++ b/DemoXMLSerialisierung/src/Person.java @@ -0,0 +1,50 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * XML-Serialisierung von Objekten, S. 272 f. +*/ + +public class Person { + private String name; + private String vorname; + private int alter; + + public Person() {} + + public Person(String name, + String vorname, int alter) + { + this.name = name; + this.vorname = vorname; + this.alter = alter; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getVorname() + { + return vorname; + } + + public void setVorname(String vorname) + { + this.vorname = vorname; + } + + public int getAlter() + { + return alter; + } + + public void setAlter(int alter) + { + this.alter = alter; + } +} \ No newline at end of file diff --git a/Eingabe/.vscode/settings.json b/Eingabe/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/Eingabe/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/Eingabe/README.md b/Eingabe/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/Eingabe/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/Eingabe/src/Eingabe.java b/Eingabe/src/Eingabe.java new file mode 100644 index 0000000..323299a --- /dev/null +++ b/Eingabe/src/Eingabe.java @@ -0,0 +1,30 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Liest einen Text aus einer Textdatei, S. 251 f. +*/ + +import java.io.*; + +public class Eingabe { + public static void main(String [] args) { + String name; + int geburtsjahr; + + // Objekt für Konsole beschaffen + Console cons = System.console(); + + // Daten ausgaben und einlesen + cons.printf("\n"); + cons.printf(" Geben Sie Ihren vollständigen Namen ein: "); + name = cons.readLine(); + + cons.printf(" Geben Sie Ihr Geburtstagsjahr ein: "); + String eingabe = cons.readLine(); + geburtsjahr = Integer.parseInt(eingabe); + cons.printf("\n"); + + cons.printf(" %1$s, %2$d war ein sehr guter Jahrgang!", + name, geburtsjahr); + cons.printf("\n"); + } +} \ No newline at end of file diff --git a/Eingabe_BufferedReader/.vscode/settings.json b/Eingabe_BufferedReader/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/Eingabe_BufferedReader/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/Eingabe_BufferedReader/README.md b/Eingabe_BufferedReader/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/Eingabe_BufferedReader/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/Eingabe_BufferedReader/src/Eingabe_BufferedReader.java b/Eingabe_BufferedReader/src/Eingabe_BufferedReader.java new file mode 100644 index 0000000..27db70e --- /dev/null +++ b/Eingabe_BufferedReader/src/Eingabe_BufferedReader.java @@ -0,0 +1,17 @@ +import java.io.*; + +public class Eingabe_BufferedReader { + public static void main(String [] args) throws IOException { + int zahl; + + System.out.println(); + System.out.print(" Geben Sie einen Integer-Wert ein: "); + BufferedReader tastatur = + new BufferedReader(new InputStreamReader(System.in)); + String eingabe = tastatur.readLine(); + + zahl = Integer.parseInt(eingabe); + System.out.println(" " + zahl); + System.out.println(); + } +} \ No newline at end of file diff --git a/Eingabe_Scanner/.vscode/settings.json b/Eingabe_Scanner/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/Eingabe_Scanner/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/Eingabe_Scanner/README.md b/Eingabe_Scanner/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/Eingabe_Scanner/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/Eingabe_Scanner/src/Eingabe_Scanner.java b/Eingabe_Scanner/src/Eingabe_Scanner.java new file mode 100644 index 0000000..b493c17 --- /dev/null +++ b/Eingabe_Scanner/src/Eingabe_Scanner.java @@ -0,0 +1,17 @@ +import java.util.Scanner; + +public class Eingabe_Scanner { + public static void main(String [] args) { + + System.out.println(); + System.out.print(" Geben Sie einen Integer-Wert ein: "); + + Scanner sc = new Scanner(System.in); + int zahl = sc.nextInt(); + + sc.close(); + + System.out.println(" Sie haben " + zahl + " eingegeben"); + System.out.println(); + } +} \ No newline at end of file diff --git a/LeseDatei/.DS_Store b/LeseDatei/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d4f135c6aea661bcde106a5e891d913102d65444 GIT binary patch literal 6148 zcmeHKO;6iE5S_&V91v0tRPCjbC9V;l5u)nFq~XAU3$DrmP>69vtr{mef593)#rH6rq%jFlw}F9`ctpUIq9*s1s# z`ZCURj1@o5iDSSqFzXEP-t{P^l=8!DV*l>Lvwm;H6d_UZu(*+3eiz?lY0=-@{IBM` z%KXBjzvwUf=h06+jQXAaplEh_r@Z>EbrwI)JMoXSJ8aihzv;Z+N%L;cB&10fA!jFP zp6Fpy5Aviixsi4FRlnMsf=$U&1fyanGsA#v5Px}QzQ}!uW56*mD-7`Y5I`A2!P25RIxv_P z09b+92)1^AD*gmD0$;!rU?^BxgazV$1Pl#sa16XD0}q!FutNX< literal 0 HcmV?d00001 diff --git a/LeseDatei/.vscode/settings.json b/LeseDatei/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/LeseDatei/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/LeseDatei/README.md b/LeseDatei/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/LeseDatei/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/LeseDatei/src/LeseDatei.java b/LeseDatei/src/LeseDatei.java new file mode 100644 index 0000000..cd55ded --- /dev/null +++ b/LeseDatei/src/LeseDatei.java @@ -0,0 +1,40 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Liest einen Text aus einer Textdatei, S. 251 f. +*/ + +import java.io.*; + +class LeseDatei +{ + public static void main(String [] args) + { + FileReader eineEingabeDatei = null; + try { + eineEingabeDatei = + new FileReader("LeseDatei/src/LeseDatei.java"); + int c; + while((c = eineEingabeDatei.read()) + != -1) + System.out.print((char) c); + } + catch(IOException eineAusnahme) + { + System.out.println( + "Fehlermeldung: " + eineAusnahme); + } + finally // Schliessen der Datei + { + if(eineEingabeDatei != null) + try + { + eineEingabeDatei.close(); + } + catch(IOException eineAusnahme) + { + System.out.println("Fehlermeldung: " + + eineAusnahme); + } + } + } + } \ No newline at end of file diff --git a/LeseDatei2/.vscode/settings.json b/LeseDatei2/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/LeseDatei2/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/LeseDatei2/README.md b/LeseDatei2/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/LeseDatei2/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/LeseDatei2/src/LeseDatei2.java b/LeseDatei2/src/LeseDatei2.java new file mode 100644 index 0000000..35f131e --- /dev/null +++ b/LeseDatei2/src/LeseDatei2.java @@ -0,0 +1,26 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Liest einen Text aus einer Textdatei, S. 252 f. +*/ + +import java.io.FileReader; +import java.io.IOException; + +class LeseDatei2 +{ + public static void main(String args []) + { + try(FileReader eineEingabeDatei = + new FileReader("LeseDatei2/src/LeseDatei2.java")) + { + int c; + while((c = eineEingabeDatei.read()) != -1) + System.out.print((char) c); + } + catch(IOException eineAusnahme) + { + System.out.println("Fehlermeldung: " + + eineAusnahme); + } + } +} diff --git a/LeseDateiGepuffert/.vscode/settings.json b/LeseDateiGepuffert/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/LeseDateiGepuffert/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/LeseDateiGepuffert/README.md b/LeseDateiGepuffert/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/LeseDateiGepuffert/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/LeseDateiGepuffert/src/LeseDateiGepuffert.java b/LeseDateiGepuffert/src/LeseDateiGepuffert.java new file mode 100644 index 0000000..cf590e9 --- /dev/null +++ b/LeseDateiGepuffert/src/LeseDateiGepuffert.java @@ -0,0 +1,29 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Liest einen Text aus einer Textdatei gepuffert, S. 253 f. +*/ + +import java.io.*; + +class LeseDateiGepuffert +{ + public static void main(String [] args) + { + try (BufferedReader eineEingabeDatei = + new BufferedReader(new FileReader( + "LeseDateiGepuffert/src/LeseDateiGepuffert.java"))){ + + String zeile = eineEingabeDatei.readLine(); + + while(zeile != null) { + System.out.println(zeile); + zeile = eineEingabeDatei.readLine(); + } + } + catch(IOException eineAusnahme) + { + System.out.println("Fehlermeldung: " + + eineAusnahme); + } + } +} \ No newline at end of file diff --git a/LeseDateiMitZeilennr/.vscode/settings.json b/LeseDateiMitZeilennr/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/LeseDateiMitZeilennr/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/LeseDateiMitZeilennr/README.md b/LeseDateiMitZeilennr/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/LeseDateiMitZeilennr/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/LeseDateiMitZeilennr/src/LeseDateiMitZeilennr.java b/LeseDateiMitZeilennr/src/LeseDateiMitZeilennr.java new file mode 100644 index 0000000..1e063f9 --- /dev/null +++ b/LeseDateiMitZeilennr/src/LeseDateiMitZeilennr.java @@ -0,0 +1,26 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Beispiel für eine Dateiausgabe mit Zeilennummern ab 100, S. 255 +*/ + +import java.io.*; + +class LeseDateiMitZeilennr +{ + public static void main(String [] args) + { + try (LineNumberReader eineEingabeDatei = new LineNumberReader(new FileReader("LeseDateiMitZeilennr/src/LeseDateiMitZeilennr.java"))){ + String zeile = eineEingabeDatei.readLine(); + eineEingabeDatei.setLineNumber(100); + + while(zeile != null) { + System.out.println(eineEingabeDatei.getLineNumber() + ": " + zeile); + zeile = eineEingabeDatei.readLine(); + } + } + catch(IOException eineAusnahme) + { + System.out.println("Fehlermeldung: " + eineAusnahme); + } + } +} \ No newline at end of file diff --git a/Roemisch/.vscode/settings.json b/Roemisch/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/Roemisch/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/Roemisch/README.md b/Roemisch/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/Roemisch/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/Roemisch/src/Roemisch.java b/Roemisch/src/Roemisch.java new file mode 100644 index 0000000..3f8ce1d --- /dev/null +++ b/Roemisch/src/Roemisch.java @@ -0,0 +1,24 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Beispiel für Aufzählungen mit Attributen, S. 238 +*/ + +public class Roemisch { + public enum Roman { + I(1), V(5), X(20), L(50), C(100), + D(500), M(1000); + private final int wert; + + Roman(int wert) { + this.wert = wert; } + + public int getWert() { + return wert; } + } + public static void main(String [] args) { + for(Roman r : Roman.values()) { + System.out.println(r.getWert() + + "\t" + r.ordinal()); + } + } +} diff --git a/SchreibeDatei/.vscode/settings.json b/SchreibeDatei/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/SchreibeDatei/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/SchreibeDatei/README.md b/SchreibeDatei/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/SchreibeDatei/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/SchreibeDatei/src/SchreibeDatei.java b/SchreibeDatei/src/SchreibeDatei.java new file mode 100644 index 0000000..5de4cff --- /dev/null +++ b/SchreibeDatei/src/SchreibeDatei.java @@ -0,0 +1,26 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Schreibt einen Text in eine Textdatei, S. 256 f. +*/ + +import java.io.*; + +class SchreibeDatei +{ + public static void main(String [] args) + { + try (FileWriter eineAusgabeDatei = + new FileWriter("SchreibeDatei/src/Schreibedatei.txt")){ + + eineAusgabeDatei + .write("Erste Zeile Text\n"); + eineAusgabeDatei + .write("Zweite Zeile Text\n"); + } + catch(IOException eineAusnahme) + { + System.out.println("Fehlermeldung: " + + eineAusnahme); + } + } +} \ No newline at end of file diff --git a/SchreibeDatei/src/Schreibedatei.txt b/SchreibeDatei/src/Schreibedatei.txt new file mode 100644 index 0000000..0114fed --- /dev/null +++ b/SchreibeDatei/src/Schreibedatei.txt @@ -0,0 +1,2 @@ +Erste Zeile Text +Zweite Zeile Text diff --git a/SchreibeDateiMitPrintWriter/.vscode/settings.json b/SchreibeDateiMitPrintWriter/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/SchreibeDateiMitPrintWriter/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/SchreibeDateiMitPrintWriter/README.md b/SchreibeDateiMitPrintWriter/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/SchreibeDateiMitPrintWriter/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/SchreibeDateiMitPrintWriter/src/MesswerteDatei.txt b/SchreibeDateiMitPrintWriter/src/MesswerteDatei.txt new file mode 100644 index 0000000..9f9b02c --- /dev/null +++ b/SchreibeDateiMitPrintWriter/src/MesswerteDatei.txt @@ -0,0 +1,2 @@ +200.32 +55.43 diff --git a/SchreibeDateiMitPrintWriter/src/SchreibeDateiMitPrintWriter.java b/SchreibeDateiMitPrintWriter/src/SchreibeDateiMitPrintWriter.java new file mode 100644 index 0000000..4f98674 --- /dev/null +++ b/SchreibeDateiMitPrintWriter/src/SchreibeDateiMitPrintWriter.java @@ -0,0 +1,23 @@ +/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren" + * W3L-Verlag Dortmund, 3. Auflage, 2014 + * Schreibt double-Literale in eine Textdatei, S. 257 f. +*/ + +import java.io.*; + +class SchreibeDateiMitPrintWriter +{ + public static void main(String [] args) + { + try (PrintWriter eineAusgabeDatei = + new PrintWriter("SchreibeDateiMitPrintWriter/src/MesswerteDatei.txt")){ + eineAusgabeDatei.println(200.32); + eineAusgabeDatei.println(55.43); + } + catch(IOException eineAusnahme) + { + System.out.println("Fehlermeldung: " + + eineAusnahme); + } + } +} \ No newline at end of file