Java.io詳解

來源:互聯網
上載者:User

一.Input和Output

1. stream代表的是任何有能力產出資料的資料來源,或是任何有能力接收資料的接收源。在Java的IO中,所有的stream(包括Input和Out stream)都包括兩種類型:

1.1 以位元組為導向的stream

以位元組為導向的stream,表示以位元組為單位從stream中讀取或往stream中寫入資訊。以位元組為導向的stream包括下面幾種類型:

1) input stream:

1) ByteArrayInputStream:把記憶體中的一個緩衝區作為InputStream使用

2) StringBufferInputStream:把一個String對象作為InputStream

3) FileInputStream:把一個檔案作為InputStream,實現對檔案的讀取操作

4) PipedInputStream:實現了pipe的概念,主要線上程中使用

5) SequenceInputStream:把多個InputStream合并為一個InputStream

2) Out stream

1) ByteArrayOutputStream:把資訊存入記憶體中的一個緩衝區中

2) FileOutputStream:把資訊存入檔案中

3) PipedOutputStream:實現了pipe的概念,主要線上程中使用

4) SequenceOutputStream:把多個OutStream合并為一個OutStream

1.2 以Unicode字元為導向的stream

以Unicode字元為導向的stream,表示以Unicode字元為單位從stream中讀取或往stream中寫入資訊。以Unicode字元為導向的stream包括下面幾種類型:

1) Input Stream

1) CharArrayReader:與ByteArrayInputStream對應

2) StringReader:與StringBufferInputStream對應

3) FileReader:與FileInputStream對應

4) PipedReader:與PipedInputStream對應

2) Out Stream

1) CharArrayWrite:與ByteArrayOutputStream對應

2) StringWrite:無與之對應的以位元組為導向的stream

3) FileWrite:與FileOutputStream對應

4) PipedWrite:與PipedOutputStream對應

以字元為導向的stream基本上對有與之相對應的以位元組為導向的stream。兩個對應類實現的功能相同,字是在操作時的導向不同。如CharArrayReader:和ByteArrayInputStream的作用都是把記憶體中的一個緩衝區作為InputStream使用,所不同的是前者每次從記憶體中讀取一個位元組的資訊,而後者每次從記憶體中讀取一個字元。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.