diff --git a/uebungen/u24/DoubleSpace.class b/uebungen/u24/DoubleSpace.class index 544f14f..80161ad 100644 Binary files a/uebungen/u24/DoubleSpace.class and b/uebungen/u24/DoubleSpace.class differ 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(); + + } + } }