u24 b
This commit is contained in:
parent
7b547be58e
commit
4af4b837b7
Binary file not shown.
|
@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue