我如何通过java.net.Socket.Socket读写德国的“ Umlaute”和诸如é之类的特殊字符?

时间:2019-11-27 23:22:55

标签: java sockets server character-encoding

我正在努力解决字符集问题。我运行带有java.net.Socket.Socket连接和JavaFX客户端的Java Server。我(当前)在双方都使用PrintWriter和BufferedReader进行通信。但是,当我发送诸如“ÄÄÄ”之类的东西并将其发送到服务器上的控制台时,我得到“Ã?Ã?Ã?”。我的代码是这样的:

//on both sides ... also tried with UTF_8 - result was also like this
writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_16));
reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_16));

//client writes
writer.write("ÄÄÄ");
writer.flush();
//... and reads
line = reader.readLine()
//server the same

要正确发送德语的爱慕乐或带有重音符号的字母,我应该怎么做?

0 个答案:

没有答案