:乱码
window下,默认采用GBK格式编码,
linux下,默认采用utf-8格式编码。
(1):如果本地sdcard文件出现乱码,可将其导出,打开,--------文件-----------另存为---------(选择编码格式)----再保存;
(2):另:
InputStreamReader reader=new InputStreamReader(inr,"utf-8"); 解决
(3):
String sssString=EncodingUtils.getString(sb.toString().getBytes(), "utf-8");
或
String sssString=EncodingUtils.getString(sb.toString().getBytes(), "gb2312");
选用何种方式要看编译环境的编译格式要和接收,发送的数据格式保持一致
(4):网络发送接收汉字出现乱码:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/plain;charset=utf-8");
PrintWriter out = response.getWriter();
name = new String(request.getParameter("name").getBytes("ISO-8859-1"), "utf-8");
age = request.getParameter("age");
System.out.println("name:"+name);
System.out.println("age:"+age);
if (name.equals("张三") && age.equals("23"))
{
out.write("登录成功");
System.out.println("登录成功浏览");
out.write("{\"id\":23,\"name\":\"zhangsan\"}");
} else {
out.write("失败:你好吗。。。。。。");
}
}
}
(5):URL中汉字的输入方式:
String serverurl = "http://192.168.4.84:9999/Test/servlet/AddUser?name="+
URLEncoder.encode("张三", "utf-8")+"&age=222";
获得数据:
System.out.println(sb.toString());
System.out.println(
URLDecoder.decode(sb.toString(), "utf-8"));