这一类别包括的类决定了我们的输入往何处去:
一个字节数组(但没有String;假定我们可用字节数组创建一个);
一个文件;或者一个“管道”。
除此以外,FilterOutputStream为“破坏器”类提供了一个基础类,它将属性或者有用的接口同输出流连接起来。这将在以后讨论。
表10.2 OutputStream的类型
Class |
Function |
Constructor Arguments |
---|---|---|
How to use it | ||
ByteArray-OutputStream |
Creates a buffer in memory. All the data that you send to the stream is placed in this buffer. |
Optional initial size of the buffer. |
To designate the destination of your data. Connect it to a FilterOutputStream object to provide a useful interface. | ||
File-OutputStream |
For sending information to a file. |
A String representing the file name, or a File or FileDescriptor object. |
To designate the destination of your data. Connect it to a FilterOutputStream object to provide a useful interface. | ||
Piped-OutputStream |
Any information you write to this automatically ends up as input for the associated PipedInput-Stream. Implements the “piping” concept. |
PipedInputStream |
To designate the destination of your data for multithreading. Connect it to a FilterOutputStream object to provide a useful interface. | ||
Filter-OutputStream |
Abstract class which is an interface for decorators that provide useful functionality to the other OutputStream classes. See Table |
See Table 10-4. |
See Table 10-4. |
类 功能 构建器参数/如何使用
ByteArrayOutputStream 在内存中创建一个缓冲区。我们发送给流的所有数据都会置入这个缓冲区。 可选缓冲区的初始大小/用于指出数据的目的地。若将其同FilterOutputStream对象连接到一起,可提供一个有用的接口
FileOutputStream 将信息发给一个文件 用一个String代表文件名,或选用一个File或FileDescriptor对象/用于指出数据的目的地。若将其同FilterOutputStream对象连接到一起,可提供一个有用的接口
PipedOutputStream 我们写给它的任何信息都会自动成为相关的PipedInputStream的输出。实现了“管道化”的概念 PipedInputStream/为多线程处理指出自己数据的目的地/将其同FilterOutputStream对象连接到一起,便可提供一个有用的接口
FilterOutputStream 对作为破坏器接口使用的类进行抽象处理;那个破坏器为其他OutputStream类提供了有用的功能。参见表10.4