标签:android socket 字符集 printwriter bufferedreader
项目中用到了Android和C++的通信,选择了用socket 发送字符的方式,一开始使用的代码是:
socket=new Socket(); InetSocketAddress isa = new InetSocketAddress(IP_STR, port); socket.connect(isa, 100); PrintWriter out=new PrintWriter(socket.getOutputStream(),true); BufferedReader recvBuf=new BufferedReader(new InputStreamReader(socket.getInputStream()));
最后将程序改为:
socket=new Socket(); InetSocketAddress isa = new InetSocketAddress(IP_STR, port); socket.connect(isa, 100); PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(),"gb2312")),true); BufferedReader recvBuf=new BufferedReader(new InputStreamReader(socket.getInputStream(),"gb2312"));
Android socket 使用PrintWriter和BufferedReader发送和接收出现乱码问题解决,布布扣,bubuko.com
Android socket 使用PrintWriter和BufferedReader发送和接收出现乱码问题解决
标签:android socket 字符集 printwriter bufferedreader
原文地址:http://blog.csdn.net/yxg190221/article/details/28102797