做爰高潮a片〈毛片〉,尤物av天堂一区二区在线观看,一本久久A久久精品VR综合,添女人荫蒂全部过程av

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

java socket中文亂碼

來源:懂視網 責編:李贏贏 時間:2021-12-24 15:43:54
文檔

java socket中文亂碼

可以使用代碼:in = new BufferedReader(new InputStreamReader(socket.getInputStream(),"UTF-8"));out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(),"UTF-8"));解決。
推薦度:
導讀可以使用代碼:in = new BufferedReader(new InputStreamReader(socket.getInputStream(),"UTF-8"));out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(),"UTF-8"));解決。

java socket中文亂碼怎么解決呢?不知道的小伙伴來看看小編今天的分享吧!

可以使用代碼:

in = new BufferedReader(new InputStreamReader(socket.getInputStream(),"UTF-8"));

out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(),"UTF-8"));

示例:

解決前:

import java.io.*;

import java.net.*; 

public class SocketServerEx1 {

public static void main(String args[]) {

System.out.println("Server");

ServerSocket serverSocket = null;

Socket clientSocket = null;

int connects = 0;

try {

serverSocket = new ServerSocket(82, 5); //端口:82,最大鏈接數:5

//最多連接10次

while(connects < 10) {

connects++;

System.out.println("--------------------等待連接--------------------------");

clientSocket = serverSocket.accept(); //等待連接

System.out.println("第 " + connects + " 次連接");

ServiceClient(clientSocket);

}

serverSocket.close();

} catch(IOException ioe) {

System.out.println("Error: " + ioe);

}}

public static void ServiceClient(Socket client) throws IOException {

System.out.println("已鏈接");

InputStreamReader inSR = null;

OutputStreamWriter outSW = null;

try {

//讀取數據

inSR = new InputStreamReader(client.getInputStream(), "UTF-8");

BufferedReader br = new BufferedReader(inSR);

outSW = new OutputStreamWriter(client.getOutputStream(), "UTF-8");

BufferedWriter bw = new BufferedWriter(outSW);

String str = "";

while((str = br.readLine()) != null) {

str = str.trim();

System.out.println("收到客戶端消息:" + str);

bw.write("已收到信息:" + str + " \r\n"); //向客戶端反饋消息,加上分行符以便客戶端接收

bw.flush();

}

} finally {

//System.out.println("Cleaning up connection: " + client);

inSR.close();

outSW.close();

client.close();

}

System.out.println("已斷開");

}

}

解決后:

import java.io.*;

import java.net.*;

 public class SocketClientEx1 {

public static void main(String[] args) {

System.out.println("Client");

try {

Socket clientSocket = new Socket("localhost", 82);

System.out.println("Client1:" + clientSocket);

DataInputStream dataIS = new DataInputStream(clientSocket.getInputStream());

InputStreamReader inSR = new InputStreamReader(dataIS, "UTF-8");

BufferedReader br = new BufferedReader(inSR);

DataOutputStream dataOS = new DataOutputStream(clientSocket.getOutputStream());

BufferedWriter bw = new BufferedWriter(outSW);

//輸入信息

byte bytes[] = new byte[100];

while(true) {

System.out.println("----------------------------------");

System.in.read(bytes);

String str = new String(bytes);

str = str.trim();

if (str == "exit") {

break;

}

//發送數據

bw.write(str + "\r\n"); //加上分行符,以便服務器按行讀取

bw.flush();

//接收數據

while((str = br.readLine()) != null) {

str = str.trim();

System.out.println("服務器回復:" + str);

break;

}

}

inSR.close();

dataIS.close();

dataOS.close();

clientSocket.close();

} catch(UnknownHostException uhe) {

System.out.println("Error:" + uhe.getMessage());

} catch(ConnectException ce) {

System.out.println("Error:" + ce.getMessage());

} catch(IOException ioe) {

System.out.println("Error:" + ioe.getMessage());

} finally {

}

}

}

以上就是小編今天的分享了,希望可以幫助到大家。

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

java socket中文亂碼

可以使用代碼:in = new BufferedReader(new InputStreamReader(socket.getInputStream(),"UTF-8"));out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(),"UTF-8"));解決。
推薦度:
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 安国市| 建始县| 溧水县| 加查县| 清流县| 永顺县| 永川市| 龙岩市| 定南县| 嵊州市| 西乌珠穆沁旗| 喀什市| 富裕县| 莎车县| 云浮市| 通城县| 宜都市| 金湖县| 霍林郭勒市| 泊头市| 盐池县| 宜良县| 屏山县| 什邡市| 东兴市| 仙桃市| 东乌| 夹江县| 江西省| 化隆| 盐津县| 崇信县| SHOW| 囊谦县| 南召县| 扎兰屯市| 许昌市| 兴隆县| 湛江市| 额济纳旗| 沅陵县|