OutputStream dekorieren
-
Hallo zusammen
hab folgenden Code spasseshalber geschrieben:import java.io.*; class SuperOutputStream { SuperOutputStream(FileOutputStream os) { this.os = os;} void writeOnlyNumbersToFileAndHaveSomeFun(String s) throws Exception { int i = 0; while ( i < s.length() ) if ( (int)s.charAt(i) < 0 || (int)s.charAt(i) > 9 ) continue; else os.write(s.charAt(i)); } private FileOutputStream os; } class NumberOutputStream { public static void main(String... args) throws Exception { SuperOutputStream os = SuperOutputStream(new FileOutputStream("numbers")); os.writeOnlyNumbersToFileAndHaveSomeFun("fase8f7a087ewf0as70f7a8fe08f7a0ea87w0e87faw87ef08972837r0"); } }
Fehlermeldung:
NumberOutputStream.java:25: cannot find symbol symbol : method SuperOutputStream(java.io.FileOutputStream) location: class NumberOutputStream SuperOutputStream os = SuperOutputStream(new FileOutputStream("numbers")); ^ 1 error
Ich nix verstehen
-
Oh je ...
Na gut, manchmal ist man wirklich so vernagelt, dass man es nicht sieht.
Man verwende new, um ein Exemplar einer Klasse zu erzeugen.
SuperOutputStream os = new SuperOutputStream(new FileOutputStream("numbers"));
-
danke