public abstract class OutputStream extends Object implements Closeable, Flushable
需要定义OutputStream子类的应用OutputStream必须至少提供一个写入一个字节输出的方法。
BufferedOutputStream , ByteArrayOutputStream , DataOutputStream , FilterOutputStream , InputStream , write(int)
| Constructor and Description |
|---|
OutputStream() |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
关闭此输出流并释放与此流相关联的任何系统资源。
|
void |
flush()
刷新此输出流并强制任何缓冲的输出字节被写出。
|
void |
write(byte[] b)
将
b.length字节从指定的字节数组写入此输出流。
|
void |
write(byte[] b, int off, int len)
从指定的字节数组写入
len个字节,从偏移
off开始输出到此输出流。
|
abstract void |
write(int b)
将指定的字节写入此输出流。
|
public abstract void write(int b)
throws IOException
write的一般合同是将一个字节写入输出流。
要写入的字节是参数b的八个低位。
b的24个高位被忽略。
OutputStream的OutputStream必须为此方法提供一个实现。
b -
byte 。
IOException - 如果发生I / O错误。
特别地,如果输出流已经被关闭,则可以抛出IOException 。
public void write(byte[] b)
throws IOException
b.length字节从指定的字节数组写入此输出流。
write(b)的一般合约是应该具有与电话write(b, 0, b.length)完全相同的效果。
b - 数据。
IOException - 如果发生I / O错误。
write(byte[], int, int)
public void write(byte[] b,
int off,
int len)
throws IOException
len字节,从偏移off开始输出到此输出流。
write(b, off, len)的一般合同是数组b中的一些字节按顺序写入输出流;
元素b[off]是写入的第一个字节, b[off+len-1]是此操作写入的最后一个字节。
该write的方法OutputStream调用写出在每个字节中的一个参数的写入方法。 鼓励子类覆盖此方法并提供更有效的实现。
如果b是null ,则抛出NullPointerException 。
如果off为负数,或len为负数,或off+len大于数组b的长度,则抛出IndexOutOfBoundsException 。
b - 数据。
off - 数据中的起始偏移量。
len - 要写入的字节数。
IOException - 如果发生I / O错误。
特别地,如果输出流关闭,则抛出IOException 。
public void flush()
throws IOException
flush的一般合同是,呼叫它表明,如果先前写入的任何字节已经通过输出流的实现进行缓冲,则这些字节应该立即被写入到它们的预定目的地。
如果此流的预期目标是由底层操作系统(例如文件)提供的抽象,那么刷新流仅保证先前写入流的字节传递到操作系统进行写入; 它并不保证它们实际上被写入物理设备,如磁盘驱动器。
该flush的方法OutputStream什么都不做。
flush在界面
Flushable
IOException - 如果发生I / O错误。
public void close()
throws IOException
close的一般合同是关闭输出流。
封闭流不能执行输出操作,无法重新打开。
该close的方法OutputStream什么都不做。
close在界面
Closeable
close在界面
AutoCloseable
IOException - 如果发生I / O错误。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.