服务器端是一个Servlet:
HttpServletResponse resp;
resp.setContentType( "text/plain;charset=UTF-8 ");
//charset=UTF-8加上和去掉最终结果一样
DataOutputStream out = new DataOutputStream(resp.getOutputStream());
System.out.println( "write..... "+resp.getCharacterEncoding());
out.writeUTF(respContext);
//respContext中有中文也有英文
//控制台显示的write.....UTF-8
客户端
InputStreamin = connection.openInputStream();
DataInputStream din = new DataInputStream(in);
String s = din.readUTF();
System.out.println( "========= "+s);
结果控制台和模拟器上显示的中文的地方都是 ?
请问这个问题怎么解决?
------解决方案--------------------------------------------------------
用字节流,别用数据流.
------解决方案--------------------------------------------------------
同上,自己做好编码转换,然后传输字节流,然后反向