为什么直接继承FileOutputStream 就会编译报错?
查了资料,改成如下形式就可以编译过。
public class AmigoOutputStream extends OutputStream
package zh.codegym.task.task18.task1813;
import java.io.*;
import java.io.FileOutputStream;
import java.io.IOException;
/*
AmigoOutputStream
*/
public class AmigoOutputStream extends OutputStream
{
private FileOutputStream comp;
public AmigoOutputStream(FileOutputStream comp){
this.comp = comp;
}
public void write(int b) throws IOException{
comp.write(b);
}
public void write(byte b[]) throws IOException {
comp.write(b);
}
public void write(byte b[], int off, int len) throws IOException {
comp.write(b, off, len);
}
public void flush() throws IOException {
comp.flush();
}
public void close() throws IOException {
comp.flush();
comp.write("CodeGym © All rights reserved.".getBytes());
comp.close();
}
public static String fileName = "C:/tmp/result.txt";
public static void main(String[] args) throws FileNotFoundException {
new AmigoOutputStream(new FileOutputStream(fileName));
}
}