Share this page 

Output accentuated characters to the consoleTag(s): IO Internationalization


Java 1.6 or more
In Java 1.6 you can use System.console() instead of System.out.println() to display accentuated characters to console.
public class Test2 {
  public static void main(String args[]){
   String s = "caractères français :  à é \u00e9"; // Unicode for "é"
   System.out.println(s);
   System.console().writer().println(s);
  }
}
anf the output is
C:\temp>java Test
caractþres franþais :  Ó Ú Ú
caractères français :  à é é
Java 1.5 or less
When starting the JVM and pass on the command line the default file encoding to be used. Then you will be able to use regular System.out.println().
java -Dfile.encoding=Cp850 MyApp
Another way is to specify in the code the encoding to be used.
import java.io.*;

public class Test {
   public static void main(String[] args) {
     PrintStream ps = null;
     String javaString =
      "caractères français :  à é \u00e9";  // Unicode for "é"

     try {
       ps = new PrintStream(System.out, true, "Cp850");
     }
     catch (UnsupportedEncodingException error) {
       System.err.println(error);
       System.exit(0);
     }
     ps.println(javaString);
   }
}

Note : List of supported encodings here