之前在網(wǎng)上大家給出的方法都是:
byte temp[] = str.getBytes("8859_1");
strResult = new String(temp, "UTF8");
但是經(jīng)過我測試,發(fā)現(xiàn)轉(zhuǎn)換不正確。沒有正確轉(zhuǎn)換成UTF。
下面給出我的實現(xiàn)方法:
1
private OutputStreamWriter outputwriter = null;
2
3
outputwriter = new OutputStreamWriter(out, "UTF-8");
4
outputwriter.write(strValue, 0, strValue.length()); 這樣就ok了,測試方法,將轉(zhuǎn)換后的字符串,用ULtra打開,進行字符轉(zhuǎn)換UTF到ASCII如果不是亂碼就OK了!
posted on 2005-08-02 15:48
jam 閱讀(1650)
評論(0) 編輯 收藏