📅  最后修改于: 2020-09-27 03:18:43             🧑  作者: Mango
Java FilterOutputStream类实现OutputStream类。它提供了不同的子类,例如BufferedOutputStream和DataOutputStream,以提供其他功能。因此,它很少单独使用。
让我们看一下java.io.FilterOutputStream类的声明:
public class FilterOutputStream extends OutputStream
Method | Description |
---|---|
void write(int b) | It is used to write the specified byte to the output stream. |
void write(byte[] ary) | It is used to write ary.length byte to the output stream. |
void write(byte[] b, int off, int len) | It is used to write len bytes from the offset off to the output stream. |
void flush() | It is used to flushes the output stream. |
void close() | It is used to close the output stream. |
import java.io.*;
public class FilterExample {
public static void main(String[] args) throws IOException {
File data = new File("D:\\testout.txt");
FileOutputStream file = new FileOutputStream(data);
FilterOutputStream filter = new FilterOutputStream(file);
String s="Welcome to javaTpoint.";
byte b[]=s.getBytes();
filter.write(b);
filter.flush();
filter.close();
file.close();
System.out.println("Success...");
}
}
输出:
Success...
testout.txt
Welcome to javaTpoint.