socket傳輸及properties中文出現亂碼解決

一、socket傳輸中文亂碼解決

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());

二、properties中文亂碼解決

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")));
相關文章
相關標籤/搜索