這一類別包括的類決定了我們的輸入往何處去:
一個位元組數組(但沒有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
10-4.
|
See Table 10-4.
|
|
See Table 10-4.
|
類 功能 構建器參數/如何使用
ByteArrayOutputStream 在記憶體中建立一個緩衝區。我們發送給流的所有資料都會置入這個緩衝區。 可選緩衝區的初始大小/用於指出資料的目的地。若將其同FilterOutputStream對象串連到一起,可提供一個有用的介面
FileOutputStream 將資訊發給一個檔案 用一個String代表檔案名稱,或選用一個File或FileDescriptor對象/用於指出資料的目的地。若將其同FilterOutputStream對象串連到一起,可提供一個有用的介面
PipedOutputStream 我們寫給它的任何資訊都會自動成為相關的PipedInputStream的輸出。實現了“管道化”的概念 PipedInputStream/為多執行緒指出自己資料的目的地/將其同FilterOutputStream對象串連到一起,便可提供一個有用的介面
FilterOutputStream 對作為破壞器介面使用的類進行抽象處理;那個破壞器為其他OutputStream類提供了有用的功能。參見表10.4