Java——IO類 字元流概述

來源:互聯網
上載者:User

標籤:fixed   ajp   cu2   key   hfs   ddb   utf-8   puts   NPU   

字元流出現的原因及思想
    ?由於位元組流操作中文不是特別方便,所以,java就提供了字元流。     ?字元流=位元組流+編碼錶。

編碼錶概述和常見的編碼錶 █ 編碼錶
      ?由字元及其對應的數值組成的一張表 █ 常見編碼錶
      ?ASCII/Unicode 字元集       ?ISO-8859-1   Latin-1       ?GB2312/GBK/GB18030       ?BIG5       ?UTF-8
public class TestMain { /* * getBytes(String charsetName);           使用指定的字元集將此 String 編碼為 byte 序列,並將結果儲存到一個新的 byte 數組中。    String(byte[] bytes, String charsetName);           通過使用指定的 charset 解碼指定的 byte 數組,構造一個新的 String。 */         public static void main(String[] args) {                 String string = "hello world" ;                        byte[] bytes = string.getBytes();   //編碼                 for(int i=0;i<bytes.length;i++){                         System.out.print(bytes[i]);   //輸出位元組碼                 }                 //解碼                 String jiemaStrin = new String(bytes);  //通過使用平台的預設字元集解碼指定的 byte 數組,構造一個新的 String。//這個平台是作業系統,預設的編碼GBK                 System.out.print('\n'+jiemaStrin);         } } public static void main(String[] args) throws UnsupportedEncodingException {                 String string = "hello world 梅浩" ;                 //編碼                 byte[] bytes = string.getBytes("utf-8");  //參數不寫就是用系統預設GBK,但是我這被改成 utf-8 了;                 for(int i=0;i<bytes.length;i++){                         System.out.print(bytes[i]);    //輸出位元組碼                 }                 //解碼                 //String jiemaStrin = new String(bytes);  //通過使用平台的預設字元集解碼指定的 byte 數組,構造一個新的 String。(我這裡已經把預設的改成utf-8了)                 String jiemaStrin = new String(bytes,"utf-8");                //這個平台是作業系統,預設的編碼GBK                 System.out.print('\n'+jiemaStrin);         } }


//unicode碼 :java 虛擬機器內部使用 String str = "梅浩";      //存字串常量區就是用 unicode 碼存的。


字元流概述(轉換流)
█ OutputStreamWriter 字元輸出資料流
     ?public OutputStreamWriter(OutputStream out);           //建立使用預設字元編碼的 OutputStreamWriter。      ?public OutputStreamWriter(OutputStream out,String charsetName);           █ InputStreamReader 字元輸入資料流
     ?public InputStreamReader(InputStream in);              //建立一個使用預設字元集的 InputStreamReader。      ?public InputStreamReader(InputStream in,String charsetName);       // 建立使用指定字元集的
  







Java——IO類 字元流概述

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.