나는 현재 등 "àéèîï"그래서의 Runnable JAR 파일 나쁜 인코딩은
와 같은 프랑스어 문자 메시지를 수신 할 필요가 소켓 서버를 실행하려고하고, 여기에 거래의 : 내 소켓 서버를 실행할 때 이클립스에서 콘솔에서 액센트를 볼 수 있기 때문에 수신 한 메시지에 올바른 인코딩이 있습니다. 그러나 소켓 서버를 실행 가능한 jar 파일로 내보내고 명령 프롬프트에서 실행하면 수신 한 메시지의 인코딩이 잘못되었습니다.
이 문제에 대한 게시물이 많이 있지만 발표 된 솔루션 중 아무 것도 나를 위해 일하지 않았거나 뭔가 누락 된 것 같습니다. 내 소켓 서버의 경우 : 여기
는 일부 코드가 매우 긴이기 때문에server = new SocketServer(port, SocketServer.ASCIIINPUT) {
@Override
public void processMessage(String message, Socket sender) throws MessageException {
try{
System.out.println("Message without decoding : " + message);
System.out.println("Message with UTF-8 decoding : " + URLDecoder.decode(message, "UTF-8"));
System.out.println("Message with ISO-8859-1 decoding : " + URLDecoder.decode(message, "ISO-8859-1"));
} catch(Exception ex){
ex.printStackTrace();
}
}
@Override
public void socketIterationDone() {}
};
내 SocketServer의 코드를 게시하지 않습니다하지만 기본적으로 그냥 연결을 관리하고 함께 BufferedReader로 구현된다
01,234,536,413 : 나는 또한 캐릭터 세트를 지정하지 않고 시도final BufferedReader reader = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF-8")));
: InputStreamReader는 다음과 같이 수신 된 메시지를 읽을 수 있어야합니다
try {
Socket s = new Socket("127.0.0.1", 6005);
s.getOutputStream().write("With UTF-8 encoding: éèï\n".getBytes(Charset.forName("UTF-8")));
s.getOutputStream().write("With ISO-8859-1 encoding: éèï\n".getBytes(Charset.forName("ISO-8859-1")));
s.getOutputStream().write("Without encoding: éèï".getBytes());
s.close();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
그래서 그 코드를 위해 그것을이다 :
은 여기 내 소켓 클라이언트입니다. 지금
C:\Users\nx_vostro_1\Desktop>java -jar test.jar
Server listening on port: 6005
Message without decoding : With UTF-8 encoding: ÚÞ´
Message with UTF-8 decoding : With UTF-8 encoding: ÚÞ´
Message with ISO-8859-1 decoding : With UTF-8 encoding: ÚÞ´
Message without decoding : With ISO-8859-1 encoding: ???
Message with UTF-8 decoding : With ISO-8859-1 encoding: ???
Message with ISO-8859-1 decoding : With ISO-8859-1 encoding: ???
Message without decoding : Without encoding: ??
Message with UTF-8 decoding : Without encoding: ??
Message with ISO-8859-1 decoding : Without encoding: ??
C:\Users\nx_vostro_1\Desktop>java -Dfile.encoding=UTF-8 -jar test.jar
Server listening on port: 6005
Message without decoding : With UTF-8 encoding: ├®├¿├»
Message with UTF-8 decoding : With UTF-8 encoding: ├®├¿├»
Message with ISO-8859-1 decoding : With UTF-8 encoding: ├®├¿├»
Message without decoding : With ISO-8859-1 encoding: ´┐¢´┐¢´┐¢
Message with UTF-8 decoding : With ISO-8859-1 encoding: ´┐¢´┐¢´┐¢
Message with ISO-8859-1 decoding : With ISO-8859-1 encoding: ´┐¢´┐¢´┐¢
Message without decoding : Without encoding: ´┐¢´┐¢
Message with UTF-8 decoding : Without encoding: ´┐¢´┐¢
Message with ISO-8859-1 decoding : Without encoding: ´┐¢´┐¢
C:\Users\nx_vostro_1\Desktop>java -Dfile.encoding=ISO-8859-1 -jar test.jar
Server listening on port: 6005
Message without decoding : With UTF-8 encoding: ÚÞ´
Message with UTF-8 decoding : With UTF-8 encoding: ÚÞ´
Message with ISO-8859-1 decoding : With UTF-8 encoding: ÚÞ´
Message without decoding : With ISO-8859-1 encoding: ???
Message with UTF-8 decoding : With ISO-8859-1 encoding: ???
Message with ISO-8859-1 decoding : With ISO-8859-1 encoding: ???
Message without decoding : Without encoding: ??
Message with UTF-8 decoding : Without encoding: ??
Message with ISO-8859-1 decoding : Without encoding: ??
그리고를 내 SocketServer 클래스의 캐릭터 세트를 지정하지 않는 경우 :
C:\Users\nx_vostro_1\Desktop>java -jar test.jar
Server listening on port: 6005
Message without decoding : With UTF-8 encoding: ├®├¿├»
Message with UTF-8 decoding : With UTF-8 encoding: ├®├¿├»
Message with ISO-8859-1 decoding : With UTF-8 encoding: ├®├¿├»
Message without decoding : With ISO-8859-1 encoding: ÚÞ´
Message with UTF-8 decoding : With ISO-8859-1 encoding: ÚÞ´
Message with ISO-8859-1 decoding : With ISO-8859-1 encoding: ÚÞ´
Message without decoding : Without encoding: ÚÞ´
Message with UTF-8 decoding : Without encoding: ÚÞ´
Message with ISO-8859-1 decoding : Without encoding: ÚÞ´
C:\Users\nx_vostro_1\Desktop>java -Dfile.encoding=UTF-8 -jar test.jar
Server listening on port: 6005
Message without decoding : With UTF-8 encoding: ├®├¿├»
Message with UTF-8 decoding : With UTF-8 encoding: ├®├¿├»
Message with ISO-8859-1 decoding : With UTF-8 encoding: ├®├¿├»
Message without decoding : With ISO-8859-1 encoding: ´┐¢´┐¢´┐¢
Message with UTF-8 decoding : With ISO-8859-1 encoding: ´┐¢´┐¢´┐¢
Message with ISO-8859-1 decoding : With ISO-8859-1 encoding: ´┐¢´┐¢´┐¢
Message without decoding : Without encoding: ´┐¢´┐¢
Message with UTF-8 decoding : Without encoding: ´┐¢´┐¢
Message with ISO-8859-1 decoding : Without encoding: ´┐¢´┐¢
C:\Users\nx_vostro_1\Desktop>java -Dfile.encoding=ISO-8859-1 -jar test.jar
Server listening on port: 6005
Message without decoding : With UTF-8 encoding: ├®├¿├»
Message with UTF-8 decoding : With UTF-8 encoding: ├®├¿├»
Message with ISO-8859-1 decoding : With UTF-8 encoding: ├®├¿├»
Message without decoding : With ISO-8859-1 encoding: ÚÞ´
Message with UTF-8 decoding : With ISO-8859-1 encoding: ÚÞ´
Message with ISO-8859-1 decoding : With ISO-8859-1 encoding: ÚÞ´
Message without decoding : Without encoding: ÚÞ´
Message with UTF-8 decoding : Without encoding: ÚÞ´
Message with ISO-8859-1 decoding : Without encoding: ÚÞ´
내 SocketServer 클래스의 캐릭터 세트의 UTF-8을 지정할 때 이제 명령 프롬프트에서 내 결과가있다 내가 desesperate, 나는 적어도 30 시간 동안이 버그를 해결하는 시도하고, 내가 인터넷에서 발견 된 모든 솔루션을 시도했지만 그들 중 누구도 일하지 :(
, 나는 도움이 필요하세요!
고맙습니다. Raphael
와우 당신이 옳습니다. 제 데이터에 올바른 인코딩이 있습니다. 올바른 출력 인코딩이없는 DOS 창일뿐입니다. 내 데이터를 파일에 쓰려고 시도하고 올바른 인코딩으로 텍스트를 표시 한 다음 내 jar 파일을 실행할 때 CP850을 지정하려고 시도하고 올바른 문자를 표시하려고했습니다. 고마워 Christoffer! –