[情報] 關於UTF-8轉成Big5

看板bioinfo_lab作者 (萊姆酒)時間18年前 (2006/01/20 12:37), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
Httpclient預設用UTF-8編碼 如果想要正確顯示中文 要自己做轉換 轉換的程式碼如下 : StringBuffer sb = new StringBuffer() ; InputStream inStream = iget.getResponseBodyAsStream() ; if ( inStream == null ) throw new Exception( "呼叫的網頁沒有 response body" ) ; int ch ; ch = inStream.read() ; while ( ch != -1 ) { sb.append( ( char ) ch ) ; ch = inStream.read() ; } //將資料轉換成big5編碼 String returnedData = "" ; returnedData = new String( sb.toString().getBytes( "ISO-8859-1" ), "BIG5" ) ; System.out.println(returnedData); iget.releaseConnection() ; 註: iget是一個GetMethod物件 ( GetMethod iget = new GetMethod() ; ) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.170.20.139
文章代碼(AID): #13q6ZjLC (bioinfo_lab)