4) GBK 中國國標(biāo),支持20000+ 中日韓英, 英文1Byte編碼, 中2Byte與unicode不兼容, 需要碼表轉(zhuǎn)換(散列表查詢)
char[] = ['A','B','中'] //4e2d
GBK(GB2312): {41,42,d6,d0}
5 認(rèn)識文本和文本文件
1) java的文本(char)是16位無符號整數(shù), 是字符的unicode編碼
2) 文件是byte by byte 的數(shù)據(jù)序列
3) 文本文件是 文本char 序列按照某種(utf-8, utf-16be, gbk)方案序列化為byte, 的存儲結(jié)果.
6 字符流(Reader Writer)
1) 字符的處理, 一次處理一個字符(unicode)
2) 字符的底層仍然是基本的字節(jié)流
3) 字符流的基本實現(xiàn):
InputStreamReader:完成byte流解析為char流, 按照編碼解析
OutputStreamWriter:提供char流到byte流, 按照編碼處理
4) 字符流的過濾器
是字符讀寫的功能擴(kuò)展, 極大的方便了文本的讀寫操作
BufferedReader : readLine()
PrintWriter: println()
5)讀取一個文本文件:
InputStream is = new FileInputStream("gbk.txt");
Reader in = new InputStreamReader(is);
BufferedReader reader = new BufferedReader(in);
or
BufferedReader in = new BufferedReader(new FileReader(filename));
6) 寫出一個文本文件:
PrintWriter out =
new PrintWtirer(new FileWriter(filename));
or
PrintWriter out =
new PrintWtirer(new OutputStreamWriter(new FileOutputStream(filename)));
7) 系統(tǒng)的默認(rèn)編碼 中文一般是GBK
String encoding=System.getProperty("file.encoding");
全國職稱計算機(jī)考試速成過關(guān)系列套裝:W .. 定價:¥133 優(yōu)惠價:¥133.0 更多書籍 | |
全國職稱計算機(jī)考試速成過關(guān)系列套裝:W .. 定價:¥124 優(yōu)惠價:¥124.0 更多書籍 |