I/O流

在java中,要對各類型文件或設備進行訪問,或者向文件、設備中寫入數據,那麼一定會用到I/O流。

 

1.java流類的分類

                      字節流                   字符流

輸入流:   inputStream               reader

輸出流:   outputStream             writer

 

java中的基礎流可以分爲以上4類。以上4類都擁有類似的方法:

 

     inputStream類或outputStream類共有方法

int  read       throws IOException

int  read(btye[] buffer)       throws IOException

int  read(btye[] buffer ,int  offset , int  length )       throws IOException

void  close()       throws IOException

 

     reader類或writer類共有方法

void  writer       throws IOException

void  writer(btye[] buffer)       throws IOException

void  writer(btye[] buffer ,int  offset , int  length )       throws IOException

void  close()       throws IOException

void  flush()       throws IOException    //刷新緩衝區(流管道)用的。

 

2.節點流和處理流

節點流類型

                                     字符流                               字節流

File(文件)            FileReader                        FileInputStream

                             FileWriter                          FileOutputStream

 

Memory  Array      CharArrayReader              ByteArrayInputStream

                            CharArrayWriter                ByteArrayOutputStream

 

Memory  String     StringReader

                            StringWriter

 

Piped(管道)       PipedReader                      PipedInputStream

                            PipedWriter                       PipedOutputStream

 

4.文件流

 

File(文件)            FileReader                        FileInputStream

                             FileWriter                          FileOutputStream

 

5.緩衝流

BufferFileReader(Reader in)

BufferFileReader(Reader in , int  sz)         //sz爲自定義緩衝區大小

BufferFileWriter(Writer out)

BufferFileWriter(Writer out , int  sz) 

BufferFileInputStream(InputStream in)

BufferFileInputStream(InputStream in , int sz )

BufferFileOutputStream(OutputStream  out )

BufferFileOutputStream(OutputStream  out , int  sz )

 

BufferFileReader(Reader in)提供了readLine用於讀取一行字符串。

BufferFileWriter(Writer out)提供了newLine用於輸出一行字符串。

 

6.數據流

DataInputStream和DataOutputStream都屬於處理流,分別嵌套在InputStream或OutputStream類型的節點流上。

 

7.轉換流

8.print流

9.object流

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章