<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 10.1 輸入和輸出 可將Java庫的IO類分割為輸入與輸出兩個部分,這一點在用Web瀏覽器閱讀聯機Java類文檔時便可知道。通過繼承,從`InputStream`(輸入流)派生的所有類都擁有名為`read()`的基本方法,用于讀取單個字節或者字節數組。類似地,從`OutputStream`派生的所有類都擁有基本方法`write()`,用于寫入單個字節或者字節數組。然而,我們通常不會用到這些方法;它們之所以存在,是因為更復雜的類可以利用它們,以便提供一個更有用的接口。因此,我們很少用單個類創建自己的系統對象。一般情況下,我們都是將多個對象重疊在一起,提供自己期望的功能。我們之所以感到Java的流庫(Stream Library)異常復雜,正是由于為了創建單獨一個結果流,卻需要創建多個對象的緣故。 很有必要按照功能對類進行分類。庫的設計者首先決定與輸入有關的所有類都從`InputStream`繼承,而與輸出有關的所有類都從`OutputStream`繼承。 ## 10.1.1 `InputStream`的類型 `InputStream`的作用是標志那些從不同起源地產生輸入的類。這些起源地包括(每個都有一個相關的`InputStream`子類): (1) 字節數組 (2) `String`對象 (3) 文件 (4) “管道”,它的工作原理與現實生活中的管道類似:將一些東西置入一端,它們在另一端出來。 (5) 一系列其他流,以便我們將其統一收集到單獨一個流內。 (6) 其他起源地,如Internet連接等(將在本書后面的部分講述)。 除此以外,`FilterInputStream`也屬于`InputStream`的一種類型,用它可為“析構器”類提供一個基類,以便將屬性或者有用的接口同輸入流連接到一起。這將在以后討論。 ``` Class Function Constructor Arguments How to use it ByteArray-InputStream Allows a buffer in memory to be used as an InputStream. The buffer from which to extract the bytes. As a source of data. Connect it to a FilterInputStream object to provide a useful interface. StringBuffer-InputStream Converts a String into an InputStream. A String. The underlying implementation actually uses a StringBuffer. As a source of data. Connect it to a FilterInputStream object to provide a useful interface. File-InputStream For reading information from a file. A String representing the file name, or a File or FileDescriptor object. As a source of data. Connect it to a FilterInputStream object to provide a useful interface. ``` | 類 | 功能 | 構造器參數/如何使用 | | --- | --- | --- | | `ByteArrayInputStream |` 允許內存中的一個緩沖區作為`InputStream`使用 | 從中提取字節的緩沖區/作為一個數據源使用。通過將其同一個`FilterInputStream`對象連接,可提供一個有用的接口 | | `StringBufferInputStream` | 將一個`String`轉換成`InputStream` | 一個`String`(字符串)。基礎的實現方案實際采用一個 | | `StringBuffer`(字符串緩沖)/作為一個數據源使用。 | 通過將其同一個FilterInputStream對象連接,可提供一個有用的接口 | | `FileInputStream` | 用于從文件讀取信息 | 代表文件名的一個`String`,或者一個`File`或`FileDescriptor`對象/作為一個數據源使用。通過將其同一個`FilterInputStream`對象連接,可提供一個有用的接口 | ``` Piped-InputStream Produces the data that’s being written to the associated PipedOutput-Stream. Implements the “piping” concept. PipedOutputStream As a source of data in multithreading. Connect it to a FilterInputStream object to provide a useful interface. Sequence-InputStream Coverts two or more InputStream objects into a single InputStream. Two InputStream objects or an Enumeration for a container of InputStream objects. As a source of data. Connect it to a FilterInputStream object to provide a useful interface. Filter-InputStream Abstract class which is an interface for decorators that provide useful functionality to the other InputStream classes. See Table 10-3. See Table 10-3. See Table 10-3. ``` | 類 | 功能 | 構造器參數/如何使用 | | --- | --- | --- | | `PipedInputString` | 產生為相關的`PipedOutputStream`寫的數據。實現了“管道化”的概念 | `PipedOutputStream`/作為一個數據源使用。通過將其同一個`FilterInputStream`對象連接,可提供一個有用的接口 | | `SequenceInputStream` | 將兩個或更多的`InputStream`對象轉換成單個`InputStream`使用 | 兩個`InputStream`對象或者一個`Enumeration`,用于`InputStream`對象的一個容器/作為一個數據源使用。通過將其同一個`FilterInputStream`對象連接,可提供一個有用的接口 | | `FilterInputStream` | 對作為析構器接口使用的類進行抽象;那個析構器為其他`InputStream`類提供了有用的功能。參見表10.3 | 參見表10.3/參見表10.3 | ## 10.1.2 `OutputStream`的類型 這一類別包括的類決定了我們的輸入往何處去:一個字節數組(但沒有`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 | 參見表10.4 |
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看