From 4af4b837b78f87657ba3af4c61315f6c4b74e52a Mon Sep 17 00:00:00 2001 From: Luca Conte Date: Thu, 1 Dec 2022 17:50:04 +0100 Subject: [PATCH] u24 b --- uebungen/u24/DoubleSpace.class | Bin 887 -> 1339 bytes uebungen/u24/DoubleSpace.java | 38 ++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/uebungen/u24/DoubleSpace.class b/uebungen/u24/DoubleSpace.class index 544f14f511097d4f43f3803a540b8e8f81df946c..80161adec6ca06d57bf0ef6c452f94e8ce2c1adb 100644 GIT binary patch delta 793 zcmY*XOHUI~6#nk?aofolY3YNi1xrDtuaQE57NjbIkqFULT{W7qozyXhQn&`rWg$oz{7>$b>&mAP-=6vVz-E+?U?)~NdBv-!u`S=;YJXU1{G2y|a z2j^r2aGv7=$CL~=5;9y!a-?KJU^ zJ=IjhRBttnhE=kfy0)cY5lad#VOc>@FpCH)xGcIx59w=0UEegVHM8BQuI^OyZObql z99I-v#fpM!SnhRMJaEvyt~F}vokvacnMS+zelTm7VaRS}mrBoDmcGT{phX#iHxGv# z+i8(OuIbi>-fC$z9Wl}}ND2c^FuF;Y>~s%Hg8^!TM?i+nE7{gzRuwbkcka!?PC15t?)Pz HCB**%)F_3= delta 364 zcmYk0yG{a85Qe|m1&cpj zo~P>`Hazsb);A0c!|}ywXxJQ2j$JCvdWlqsvdimiklkj2xw@HdG4m|A6X`@Hwqici4^DV?WkfDvwBG4oKaHEW1Z(xMGmq)6$NKHir<=(^RpntgcgZ=6lb`lP*F< zu`m^l_N-DPm`2+=eKbmfB%F}@OIvl&tidv?TTXLx%C+wAtvd?OrQ#mKVW+NsOz_3f Pkk<$0e-}bS-GId(j{+ym diff --git a/uebungen/u24/DoubleSpace.java b/uebungen/u24/DoubleSpace.java index c387c1f..ecdaa56 100644 --- a/uebungen/u24/DoubleSpace.java +++ b/uebungen/u24/DoubleSpace.java @@ -6,7 +6,7 @@ import java.util.*; */ public class DoubleSpace { public static void main(String[] args) throws FileNotFoundException { - doubleSpace("test.txt","out.txt"); + doubleSpace2("test.txt","out.txt"); } /** @@ -29,4 +29,40 @@ public class DoubleSpace { output.close(); input.close(); } + + /** + * Duplizierzt Leerzeilen bzw Zeilenumbrueche der + * Datei inputFileName und speichert das Ergebnis in + * outputFileName ab + * Inklusive Fehlerbehandlung + */ + public static void doubleSpace2(String inputFileName, String outputFileName) { + + Scanner input = null; + PrintStream output = null; + + try { + + input = new Scanner(new File(inputFileName)); + output = new PrintStream(new File(outputFileName)); + + if (input.hasNextLine()) { + output.println(input.nextLine()); + } + while (input.hasNextLine()) { + output.println(); + output.println(input.nextLine()); + } + + } catch (FileNotFoundException e) { + + System.out.println(e.getMessage()); + + } finally { + + if (output != null) output.close(); + if (input != null) input.close(); + + } + } }