我从服务器端用response.getWriter().write("中文");发送出“中文”数据,在Android客户端用以下片段接收: HttpResponse httpResponse = httpClient.execute(httpPost);
httpEntity = httpResponse.getEntity();
input = httpEntity.getContent();
byte[] buffer = new byte[1024];
int len = 0;
while((len = input.read(buffer)) != -1) {
                                // 此处老是出现乱码,得不到“中文”
                                // 而且我用(getBytes("iso-8859-1"), "utf-8")之后也不行
Log.e("数据", new String(buffer, 0, len));
}求大师解决??????????????????

解决方案 »

  1.   

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
      int len = 0;
      byte[] datas = new byte[1024];
      while((len = input.read(datas,0,1024)) != -1)
      baos.write(datas, 0, len);String str=new String(baos.toByteArray(),"iso-8859-1");
    String strUtf=new String(str.getBytes(),"UTF-8");
      

  2.   

    编码问题,客户端获取字节数组,再转换为字符串的时候指定需要的编码方式
    例如:new String(data,“UTF-8”)//data为字节数组
      

  3.   

    你服务器的编码方式也要和客户端的编码方式一直,你看看你的服务器编码方式是不是不是utf-8?