位元組流:
inputstream:位元組輸入流的超類。它中定義的讀取位元組的read方法
fileinputstream:專門負責從檔案中讀取位元組資料。
bufferedinputstream:位元組輸入流的緩衝區。
outputstream:位元組輸出流的超類。定義類的寫位元組的資料的write方法
fileoutputstream:專門負責給檔案中寫位元組資料。
bufferedoutputstream:位元組輸出流的緩衝區。
字元流:
reader:字元輸入流的超類。定義的讀取字元的read方法
inputstreamreader:將位元組根據指定的編碼表轉成字元。位元組轉字元的橋梁,屬於輸入流
filereader:便捷的字元檔案輸入流,使用本地預設的編碼表。
bufferedreader:其中有readline方法可以讀取一行資料,得到的是乙個字串
writer:字元輸出流的超類,定義的寫字元資料的write方法
outputstreamwriter:將字元資料根據指定的編碼表轉成位元組資料,字元轉位元組的橋梁,屬於輸出流。
filewriter:便捷的字元檔案輸出流,使用本地預設的編碼表。
bufferedwriter:newline方法可以寫乙個換行。
總結輸入流的模版**:
一次讀取乙個位元組(字元):
fileinputstream fis = newfileinputstream(「檔案」);
filereader fr = newfilereader(「檔案」);
int ch = 0;
while( ( ch = fis.read())!=-1 )
fis.close(); fr.close();
一次讀取多個位元組(字元):
fileinputstream fis = newfileinputstream(「檔案」);
filereader fr = newfilereader(「檔案」);
int len = 0;
byte buf = new byte[1024]; 或 char cbuf= new char[1024];
while( ( len = fis.read(buf)) !=-1 )
fis.close(); fr.close();
一次讀取一行資料
bufferedreader bufr = newbufferedreader( new filereader(「檔案」) )
bufferedreader bufr = newbufferedreader( new inputstreamreader( new fileinputstream (「檔案」) ))
string line = null;
while( ( line =bufr.readline() )!=null )
bufr.close();
1、確定流的操作的資料特點:
資料是字元資料還是位元組資料。
字元資料:字元流
位元組資料:位元組流
2、確定操作的方向:
讀取操作:輸入流
寫出操作:輸出流
3、操作的資料編碼表是否一致?
不一致,就需要使用到轉換流。
4、程式是否需要提高效率:
加上buffered相關的流物件。
IO流加強 總結 IO流總結和練習
1.流都是用來傳輸資料的。2.傳輸資料時,一定要明確資料來源和資料目的地 資料匯 3.資料來源可以是檔案 鍵盤和其他流。4.資料目的地可以是檔案 顯示器或者其他流。5,流只是幫助資料進行傳輸,可以在傳輸資料的時候進行處理。比如過濾處理 轉換處理等。使用要點 看頂層 字元流還是位元組流,父類公共性功能...
IO流 字元流 IO流小結 IO流案例總結
1 字元流 掌握 1 位元組流操作中文資料不是特別的方便,所以就出現了轉換流。轉換流的作用就是把位元組流轉換字元流來使用。2 轉換流其實是乙個字元流 字元流 位元組流 編碼表 3 編碼表 a 就是由字元和對應的數值組成的一張表 b 常見的編碼表 ascii iso 8859 1 gb2312 gbk...
IO流 位元組流和字元流總結
一.位元組流總結 1.位元組輸入流 inputstream fileinputstream 從檔案讀取位元組 bufferedinputstream 加入緩衝功能,提高檔案的讀取效率 bytearrayinputstream 讀取位元組陣列 2.位元組輸出流 outputstream fileout...