title: Encoding issue with System.out in Java
body: <p>I'm having difficulties with my logger that I embedded into a <code>JTextArea</code>: when I call the <code>logger.append()</code> method, it just works fine, but when I use <code>System.out.println()</code>, all my French accents are lost.</p>
  
  <p>Here, you have the creation of the logger and the redirection of <code>System.out</code> and <code>System.err</code> to it.</p>
  
  <pre><code>this.logger = new TextAreaOutputStream(jta, jsp.getVerticalScrollBar());
  System.setProperty("user.langage", "fr");
  PrintStream ps;
  ps = new PrintStream(this.logger, true, "UTF-8");
  System.setOut(ps);
  System.setErr(ps);
  </code></pre>
  
  <p>Here, you have the <code>TextAreaOutputStream</code> class.</p>
  
  <pre><code>import java.io.IOException;
  import java.io.OutputStream;
  import javax.swing.JScrollBar;
  import javax.swing.JTextArea;
  
  public class TextAreaOutputStream extends OutputStream {
      private JTextArea jta;
      private JScrollBar jsb;
  
      public TextAreaOutputStream(JTextArea jta, JScrollBar jsb) {
          this.jta = jta;
          this.jsb = jsb;
      }
  
      public synchronized void append(String s) {
          this.jta.append(s);
          scroll();
      }
  
      public synchronized void write(int b) throws IOException {
          jta.append(String.valueOf((char) b));
          if (((char) b) == '\n')
              scroll();
      }
  
      private synchronized void scroll() {
          if ((jsb.getValue() + jsb.getVisibleAmount()) == jsb.getMaximum()) 
              jta.setCaretPosition(jta.getDocument().getLength());
      }
  }
  </code></pre>
  
  <p>I tried to change the encoding of the <code>PrintStream</code> to random encodings, it changed the look of the misprinted accents, but I never could have it right. I also tried to change the accents with unicode entries such as <code>\u00e9</code> for <code>é</code>, but it did not change anything.</p>
  
  <p>Here, I'm desperate enough to ask for your help,</p>
  
  <p>Romain</p>