socket服務端和客戶端編碼方式不一致將有可出現中文亂碼問題,所以兩邊設成同樣的就能夠了java
socket服務端發送數據時設置編碼方式socket
PrintWriter output = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(),"UTF-8"),true); output.println("你好");
客戶端接收數據時設置編碼方式:編碼
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream(),"UTF-8")); System.out.println(input.readLine());
private static Properties prop = new Properties(); prop.load(new BufferedReader(new InputStreamReader(new FileInputStream(new File(Thread.currentThread().getContextClassLoader().getResource("").getPath()+"\\adtypes.properties")),"UTF-8")));