在我以以下方法返回字符串之前,我想将内容转换为 utf-8 字符集:
public static String getContentResult(URL url) throws IOException{
InputStream in = url.openStream();
StringBuilder sb = new StringBuilder();
byte [] buffer = new byte[4096];
while(true){
int byteRead = in.read(buffer);
if(byteRead == -1)
break;
for(int i = 0; i < byteRead; i++){
sb.append((char)buffer[i]);
}
}
in.close();
return sb.toString();
}
我怎样才能做到这一点?
谢谢!