title: Runnable JAR file bad encoding with sockets
body: <p>I am currently trying to run a socket server that needs to receive messages with french characters such as "àéèîï" etc.</p>
  
  <p>So, here's the deal : when I execute my socket server in eclipse, the messages that I receive have the right encoding because I can see the accents in the console. But when I export my socket server into a runnable jar file and execute it in a command prompt, the encoding of the messages I receive seems wrong.</p>
  
  <p>I know there is a whole lot of posts about this problem but none of the solutions presented worked for me, or maybe I am missing something.</p>
  
  <p>Here is some code :
  For my socket server :</p>
  
  <pre><code>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() {}
  
  };
  </code></pre>
  
  <p>I won't post the code of my SocketServer since it is very long but it is basically just managing connections and implementing an BufferedReader with an InputStreamReader to be able to read the received messages like this :</p>
  
  <pre><code>final BufferedReader reader = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF-8")));
  </code></pre>
  
  <p>I also tried without specifying a Charset :</p>
  
  <pre><code>final BufferedReader reader = new BufferedReader(new InputStreamReader(in));
  </code></pre>
  
  <p>Here is my socket client :</p>
  
  <pre><code>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();
      }
  </code></pre>
  
  <p>So that's it for the code. Now there are my results in the command prompt when I specify the Charset UTF-8 in my SocketServer class:</p>
  
  <pre><code>C:\Users\nx_vostro_1\Desktop&gt;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&gt;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&gt;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: ??
  </code></pre>
  
  <p>And now when I do not specify the Charset in my SocketServer class :</p>
  
  <pre><code>C:\Users\nx_vostro_1\Desktop&gt;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&gt;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&gt;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: ÚÞ´
  </code></pre>
  
  <p>I am desesperate, I tried solving this bug for at least 30 hours, I tried every solution I found on the Internet but none of them worked :(</p>
  
  <p>Please, I need help!</p>
  
  <p>Thank you,
  Raphael</p>