public abstract class OutputStream extends Object implements Closeable, Flushable
这需要定义一个类OutputStream
应用必须至少提供一个方法将输出一个字节。
BufferedOutputStream
,
ByteArrayOutputStream
,
DataOutputStream
,
FilterOutputStream
,
InputStream
,
write(int)
Constructor and Description |
---|
OutputStream() |
public abstract void write(int b) throws IOException
write
总承包是一个字节被写入输出流。字节写是争论
b
八低阶位。对
b
24阶位被忽略。
子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]
是最后一个字节写的。
对OutputStream
的write
方法调用Write方法一个论点的每个字节被写入了。鼓励子类重写此方法,并提供一个更有效的实现。
如果b
是null
,一NullPointerException
抛出。
如果off
是负的,或len
是负的,或off+len
大于数组b
的长度,然后IndexOutOfBoundsException抛出。
b
-数据。
off
的起始偏移量的数据。
len
-字节数写。
IOException
如果I/O错误发生。特别是,如果一个
IOException
输出流已被关闭。
public void flush() throws IOException
flush
一般合同,称这是一个迹象表明,,如果以前写的任何字节被输出流的实现缓冲,这些字节应该立即被写入目的地。
如果此流的预期目的地是底层操作系统提供的一个抽象,例如一个文件,然后刷新流只保证以前写入流的字节被传递给操作系统,它不保证它们实际上被写入到一个物理设备,如磁盘驱动器。
对OutputStream
的flush
方法不。
flush
接口
Flushable
IOException
如果I/O错误发生。
public void close() throws IOException
close
一般合同是关闭输出流。一个关闭流不能执行输出操作,不能重新打开。
对OutputStream
的close
方法不。
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.