您正在构建一个使用tcp的消息传递应用程序,每当我发送带有希伯来语字符的字符串时我都会得到问号,并且我已经尝试使用新的字符串转换字符串(serverMessage.getBytes()," UTF- 8&#34); 但它没有在这里工作是我的代码:
try {
//send the message to the server
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
//receive the message that the server sends back
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
HelloService.firstTouch();
//in this while the client listens for the messages sent by the server
while (mRun) {
serverMessage = in.readLine();
String temmmd = new String(serverMessage.getBytes("UTF-8"),"UTF-8");
if (serverMessage != null && mMessageListener != null) {
//call the method messageReceived from MyActivity class to inform main activity that a message has received
mMessageListener.messageReceived(temmmd);
}
serverMessage = null;
}
} catch (Exception e) {
} finally {
socket.close();
}
} catch (Exception e) {
}