public abstract class OutputStream
extends Object implements Closeable, Flushable
| java.lang.Object | |
| java.io.OutputStream | |
| |
这个抽象类是代表输出字节流的所有类的超类。 输出流接受输出字节并将它们发送到某个接收器。
需要定义 OutputStream的子类的应用程序必须始终提供至少一个写入一个字节输出的方法。
也可以看看:
Public constructors |
|
|---|---|
OutputStream() |
|
公共方法(Public methods) |
|
|---|---|
void |
close() 关闭此输出流并释放与此流关联的所有系统资源。 |
void |
flush() 刷新此输出流并强制写出所有缓冲的输出字节。 |
void |
write(byte[] b) 将指定字节数组中的 |
void |
write(byte[] b, int off, int len) 将从偏移量 |
abstract void |
write(int b) 将指定的字节写入此输出流。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
java.io.Closeable
|
|
java.io.Flushable
|
|
java.lang.AutoCloseable
|
|
void close ()
关闭此输出流并释放与此流关联的所有系统资源。 close的总体合同是关闭输出流。 封闭的流不能执行输出操作,不能重新打开。
该 close的方法 OutputStream什么都不做。
| 抛出异常(Throws) | |
|---|---|
IOException |
if an I/O error occurs. |
void flush ()
刷新此输出流并强制写出所有缓冲的输出字节。 flush的一般合约是调用它表明,如果先前写入的任何字节已被输出流的实现缓冲,则应立即将这些字节写入其预期的目的地。
如果此流的预期目标是底层操作系统提供的抽象(例如文件),则刷新流只能确保先前写入流的字节传递到操作系统进行写入; 它并不保证它们实际写入物理设备(如磁盘驱动器)。
flush方法 OutputStream什么也不做。
| 抛出异常(Throws) | |
|---|---|
IOException |
if an I/O error occurs. |
void write (byte[] b)
将指定字节数组的b.length个字节写入此输出流。 write(b)的一般合同是它应该和write(b, 0, b.length)的呼叫具有完全相同的效果。
| 参数(Parameters) | |
|---|---|
b |
byte: the data. |
| 抛出异常(Throws) | |
|---|---|
IOException |
if an I/O error occurs. |
也可以看看:
void write (byte[] b,
int off,
int len)
将从偏移量off开始的指定字节数组中的len个字节写入此输出流。 write(b, off, len)的一般合约是将数组b中的一些字节按b写入输出流; 元素b[off]是写入的第一个字节,而b[off+len-1]是此操作写入的最后一个字节。
write的OutputStream方法在每个要写出的字节上调用一个参数的写入方法。 鼓励子类覆盖此方法并提供更高效的实现。
如果 b是 null ,则引发 NullPointerException 。
如果 off为负数,或者 len为负数,或者 off+len大于数组 b的长度,则引发 IndexOutOfBoundsException 。
| 参数(Parameters) | |
|---|---|
b |
byte: the data. |
off |
int: the start offset in the data. |
len |
int: the number of bytes to write. |
| 抛出异常(Throws) | |
|---|---|
IOException |
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed. |
void write (int b)
将指定的字节写入此输出流。 write的总体合同是将一个字节写入输出流。 要写入的字节是参数b的8个低位。 忽略b的24个高位。
OutputStream子类必须提供此方法的实现。
| 参数(Parameters) | |
|---|---|
b |
int: the byte. |
| 抛出异常(Throws) | |
|---|---|
IOException |
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed. |