求助,关于socket通信,用UDP协议,乱码的问题
答案:2 悬赏:50 手机版
解决时间 2021-02-27 09:04
- 提问者网友:十年饮冰
- 2021-02-26 23:52
求助,关于socket通信,用UDP协议,乱码的问题
最佳答案
- 五星知识达人网友:千杯敬自由
- 2021-02-27 00:45
乱码问题根本就是 上传的编码 和 下载之后的解码 用的不是同一个编码
String str = "文本";
Byte[] bytes = str.getBytes("UTF-8");
然后socket传过去
收到 bytes
Streing str = new String(bytes, 0, bytes.length, "utf-8");
打印 str
String str = "文本";
Byte[] bytes = str.getBytes("UTF-8");
然后socket传过去
收到 bytes
Streing str = new String(bytes, 0, bytes.length, "utf-8");
打印 str
全部回答
- 1楼网友:从此江山别
- 2021-02-27 01:41
【解决办法】:
服务器端:
bufferedreader in = new bufferedreader(new inputstreamreader(
process.getinputstream(),"utf-8"));
printwriter out = new printwriter(new bufferedwriter(new outputstreamwriter(process.getoutputstream(),"utf-8")),true);
out.println((of.getofferfeeinfo()[i].getcumulantname());
客户端:
printwriter out =
new printwriter(new bufferedwriter(new outputstreamwriter(client.getoutputstream(),"utf-8")),true);
out.println(imsi.trim());
out.flush();
bufferedreader in = new bufferedreader(new inputstreamreader(client
.getinputstream(),"utf-8"));
result = in.readline();
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯