|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.io.Writer
public abstract class Writer
写入字符流的抽象类。子类必须实现的方法仅有 write(char[], int, int)、flush() 和 close()。但是,多数子类将重写此处定义的一些方法,以提供更高的效率和/或其他功能。
Writer,
BufferedWriter,
CharArrayWriter,
FilterWriter,
OutputStreamWriter,
FileWriter,
PipedWriter,
PrintWriter,
StringWriter,
Reader| 字段摘要 | |
|---|---|
protected Object |
lock
用于同步针对此流的操作的对象。 |
| 构造方法摘要 | |
|---|---|
protected |
Writer()
创建一个新的字符流 writer,其关键部分将同步 writer 自身。 |
protected |
Writer(Object lock)
创建一个新的字符流 writer,其关键部分将同步给定的对象。 |
| 方法摘要 | |
|---|---|
Writer |
append(char c)
将指定字符添加到此 writer。 |
Writer |
append(CharSequence csq)
将指定字符序列添加到此 writer。 |
Writer |
append(CharSequence csq,
int start,
int end)
将指定字符序列的子序列添加到此 writer.Appendable。 |
abstract void |
close()
关闭此流,但要先刷新它。 |
abstract void |
flush()
刷新该流的缓冲。 |
void |
write(char[] cbuf)
写入字符数组。 |
abstract void |
write(char[] cbuf,
int off,
int len)
写入字符数组的某一部分。 |
void |
write(int c)
写入单个字符。 |
void |
write(String str)
写入字符串。 |
void |
write(String str,
int off,
int len)
写入字符串的某一部分。 |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 字段详细信息 |
|---|
protected Object lock
| 构造方法详细信息 |
|---|
protected Writer()
protected Writer(Object lock)
lock - 要同步的对象。| 方法详细信息 |
|---|
public void write(int c)
throws IOException
用于支持高效单字符输出的子类应重写此方法。
c - 指定要写入字符的 int。
IOException - 如果发生 I/O 错误
public void write(char[] cbuf)
throws IOException
cbuf - 要写入的字符数组
IOException - 如果发生 I/O 错误
public abstract void write(char[] cbuf,
int off,
int len)
throws IOException
cbuf - 字符数组off - 开始写入字符处的偏移量len - 要写入的字符数
IOException - 如果发生 I/O 错误
public void write(String str)
throws IOException
str - 要写入的字符串
IOException - 如果发生 I/O 错误
public void write(String str,
int off,
int len)
throws IOException
str - 字符串off - 相对初始写入字符的偏移量len - 要写入的字符数
IndexOutOfBoundsException - 如果 off 或 len 为负,或者 off+len 为负或大于给定字符串的长度
IOException - 如果发生 I/O 错误
public Writer append(CharSequence csq)
throws IOException
以 out.append(csq) 的形式调用此方法,行为与以下调用完全相同:
out.write(csq.toString())
可能不添加整个序列,也可能添加,具体取决于字符序列 csq 的 toString 规范。例如,调用一个字符缓冲区的 toString 方法将返回一个子序列,其内容取决于缓冲区的位置和限制。
Appendable 中的 appendcsq - 要添加的字符串序列。如果 csq 为 null,则向此 writer 添加四个字符 "null"。
IOException - 如果发生 I/O 错误
public Writer append(CharSequence csq,
int start,
int end)
throws IOException
当 csq 不为 null 时,以 out.append(csq, start, end) 的形式调用此方法,行为与以下调用完全相同:
out.write(csq.subSequence(start, end).toString())
Appendable 中的 appendcsq - 要添加子序列的字符序列。如果 csq 为 null,则添加四个字符 "null",就好像 csq 包含这些字符一样。start - 子序列中第一个字符的索引end - 子序列中最后一个字符后面的字符的索引
IndexOutOfBoundsException - 如果 start 或 end 为负,而 start 大于 end 或者 end 大于 csq.length()
IOException - 如果发生 I/O 错误
public Writer append(char c)
throws IOException
以 out.append(c) 的形式调用此方法,行为与以下调用完全相同:
out.write(c)
Appendable 中的 appendc - 要添加的 16 位字符
IOException - 如果发生 I/O 错误
public abstract void flush()
throws IOException
如果此流的预期目标是由底层操作系统提供的一个抽象(如一个文件),则刷新该流只能保证将以前写入到流的字节传递给操作系统进行写入,但不保证能将这些字节实际写入到物理设备(如磁盘驱动器)。
Flushable 中的 flushIOException - 如果发生 I/O 错误
public abstract void close()
throws IOException
Closeable 中的 closeIOException - 如果发生 I/O 错误
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2008 Sun Microsystems, Inc. 保留所有权利。请遵守GNU General Public License, version 2 only。