鸿蒙OS开发文档 鸿蒙OS FilterWriter

2024-02-25 开发教程 鸿蒙OS开发文档 匿名 2

FilterWriter

java.lang.Object
|---java.io.Writer
|---|---java.io.FilterWriter

public abstract class FilterWriter
extends Writer

用于编写过滤字符流的抽象类。 抽象类 FilterWriter 本身提供了将所有请求传递给包含的流的默认方法。 FilterWriter 的子类应该覆盖其中的一些方法,并且还可以提供额外的方法和字段。

Since:

JDK1.1

字段摘要

修饰符和类型字段描述
protected Writerout底层字符输出流。
从类 java.io.Writer 继承的字段
lock

构造函数摘要

修饰符构造函数描述
protectedFilterWriter(Writer out)创建一个新的过滤 writer。

方法总结

修饰符和类型方法描述
voidclose()关闭流,首先刷新它。
voidflush()冲洗流。
voidwrite(char[] cbuf, int off, int len)写入字符数组的一部分。
voidwrite(int c)写入单个字符。
voidwrite(String str, int off, int len)写入字符串的一部分。
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从类 java.io.Writer 继承的方法
append, append, append, write, write

字段详细信息

out

protected Writer out

底层字符输出流。

构造函数详细信息

FilterWriter

protected FilterWriter(Writer out)

创建一个新的过滤 writer。

参数:

参数名称参数描述
out提供底层流的 Writer 对象。

Throws:

Throw名称Throw描述
NullPointerException如果 out 为空

方法详情

write

public void write(int c) throws IOException

写入单个字符。

覆盖:

在 Writer 类中写

参数:

参数名称参数描述
cint 指定要写入的字符

Throws:

Throw名称Throw描述
IOException如果发生 I/O 错误

write

public void write(char[] cbuf, int off, int len) throws IOException

写入字符数组的一部分。

指定者:

在 Writer 类中写

参数:

参数名称参数描述
cbuf要写入的字符缓冲区
off开始读取字符的偏移量
len要写入的字符数

Throws:

Throw名称Throw描述
IOException如果发生 I/O 错误

write

public void write(String str, int off, int len) throws IOException

写入字符串的一部分。

覆盖:

在 Writer 类中写

参数:

参数名称参数描述
str要写入的字符串
off开始读取字符的偏移量
len要写入的字符数

Throws:

Throw名称Throw描述
IOException如果发生 I/O 错误

flush

public void flush() throws IOException

冲洗流。

指定者:

在接口 Flushable 中刷新

指定者:

在 Writer 类中刷新

Throws:

Throw名称Throw描述
IOException如果发生 I/O 错误

close

public void close() throws IOException

从班级复制的描述:Writer

关闭流,首先刷新它。 一旦流被关闭,进一步的 write() 或 flush() 调用将导致抛出 IOException。 关闭以前关闭的流没有效果。

指定者:

在接口 AutoCloseable 中关闭

指定者:

在接口Closeable中关闭

指定者:

close in class Writer

Throws:

Throw名称Throw描述
IOException如果发生 I/O 错误