开发者

Android: UTF-8 encoded HTTP response to String

开发者 https://www.devze.com 2023-01-22 16:16 出处:网络
I am trying to convert a UTF-8 data to String. The UTF-8 data is obtained by HTTP connection. My problem is the converted String does not display UTF-8 Characters properly.

I am trying to convert a UTF-8 data to String. The UTF-8 data is obtained by HTTP connection. My problem is the converted String does not display UTF-8 Characters properly.

Here is my code {extra bits removed }

URLConnection urlconn = url.openConnection();
httpConn = (HttpURLConnection) urlconn;
httpConn.connect();
InputStream in= httpConn.getInputStream();
String text = "";
InputStreamReader isr = new Inp开发者_高级运维utStreamReader(in,"UTF-8");
int charRead;
char[] inputBuffer = new char[2048];


while((charRead = isr.read(inputBuffer))>0){
String readString = String.copyValueOf(inputBuffer,0,charRead);
text += readString;
inputBuffer = new char[BUFFER];
}

Where am i doing wrong ? The generated text is not UTF-8 !!

Thanks

0

精彩评论

暂无评论...
验证码 换一张
取 消