native的Socket向Android的LocalSocketServer发送汉字乱码的问题

native的Socket发送字节流默认是GB2312的,所以在Java方面需要指定GB2312

byte[] buffer = new byte[50];
StringBuffer strBuf = new StringBuffer();
InputStream input = receiver.getInputStream();
while((len = input.read(buffer)) != -1) {
    String newStr = new String(buffer, 0, len, "GB2312");
    strBuf.append(newStr);
}

 reference:

http://hi.baidu.com/cmdmac/item/9a6cf9dc3254dfe6795daaa9

http://www.cnblogs.com/kenkofox/archive/2010/04/23/1719009.html

http://www.cnblogs.com/uuhua/archive/2010/06/15/1758552.html

 

posted on 2012-11-19 14:23  GloriousOnion  阅读(856)  评论(0编辑  收藏  举报