輸入輸出流(IO)

2021-07-24 17:16:25 字數 619 閱讀 3767

outputstream,所有輸出位元組流的基類,抽象類

字元流 = 位元組流 + 編碼(解碼)

writer,所有輸出字元流的基類,抽象類

什麼情況下使用字元流:如果讀寫需要編碼和解碼的資料(字元資料),這時候我們就使用字元流

轉換流的作用:

可以把對應的位元組流轉換成字元流使用。

/** 將輸入控制台的一行字元資料顯示出來 */

public static void testinput() throws exception

可以指定碼表進行讀寫檔案的資料。因為filereader和filewriter這兩個類預設是使用的是gbk編碼,不能指定讀寫檔案資料的編碼。

/** 指定utf-8碼表把資料寫出到檔案上 */

public static void writefile() throws ioexception

/** 指定utf-8碼表進行讀取檔案上的資料 */

public static void readfile() throws ioexception

inputstreamreader.close();

}

輸入輸出流(IO流

流 流 stream 的概念源於 unix 中管道 pipe 的概念,在 unix 中,管道是一條不間斷的位元組流,用來實現程式或程序間的通訊,或讀寫外圍裝置 外部檔案等。重要 1.流操作結束後必須關閉。2.inputstream reader outputstream write全是抽象,不能直接...

IO 輸入輸出流

io流 輸入流位元組輸入流 inputstream fileinputstream 構造方法 fileinputstream file file fileinputstream string filename bufferedinputstream 成員方法 int read 讀乙個位元組 int ...

IO輸入輸出流

一 input 輸入 output 輸出 資料從外界進入程式叫做輸入 資料從程式流向外界叫做輸出 二 檔案的操作 檔案的增刪該查 1.檔案建立 file file newfile c io helloio.txt boolean flag file.createnewfile 建立成功返回true ...