2016年8月2日 星期二

JAVA-String編碼轉換

字串UTF-8編碼 轉Byte 數較少 的編碼例如 Big5 編碼會有失真的問題,難字也有其困難完整的轉換,將字串重新放回Write 重寫 會是解
   
   public String Convertendcode(String content){
     ByteArrayInputStream bais = new ByteArrayInputStream(content.getBytes("utf-8"));
     BufferedReader br = new BufferedReader (new InputStreanReader(bais));
     ByteArrayOutputStream boas =new ByteArrayOutputStream ();
     OutputStreamWriter osw =new OutputStreamWriter(boas,"big5");
     String buffer = null;
     if ((buufer = br.readLine())!=null){
       osw.write(buufer);
     }
     osw.flush();
     return boas.toString("big5");
   }

沒有留言:

張貼留言