私は現在、このような等「àéèîï」だから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() {}
};
、それは非常に長いですが、それは基本的には接続を管理し、とBufferedReaderのを実装しているので、私は私のSocketServerのコードを投稿しません
:私も文字セットを指定せずに試してみました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();
}
は、だから、コードのためにそれをです:
は、ここに私のソケットクライアントです。私は私のSocketServerクラスで文字セットUTF-8を指定するときに今、私の結果は、コマンドプロンプトにあります
今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: ÚÞ´
私はdesesperateだ、私は、少なくとも30時間、このバグを解決しようとした、私はインターネット上で見つかったすべてのソリューションを試みたが、それらのどれも働いていない:(
、私は助けを必要としてください!
は ラファエル
あなたは正しいです、私のデータは適切なエンコーディングを持っています、それは正しい出力エンコーディングを持っていないDOSウィンドウです。 ファイルにデータを書き込もうとしましたが、正しいエンコードでテキストが表示され、jarファイルを実行しているときにCP850を指定しようとしましたが、正しい文字が表示されていました。ありがとうChristoffer! –