Skip to content

Instantly share code, notes, and snippets.

@mattwarren
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattwarren/b560a8e1de010cfdac00 to your computer and use it in GitHub Desktop.
Save mattwarren/b560a8e1de010cfdac00 to your computer and use it in GitHub Desktop.
Console Demo showing Windows Console Encoding Issues with '±'
public class ConsoleDemo {
public static void main(String[] args) {
// From http://stackoverflow.com/questions/4005378/console-writeline-and-system-out-println/4005717#4005717
// '\u00B1' is the same as '±', see http://www.fileformat.info/info/unicode/char/b1/index.htm
String data = "%-35s: %.2f ±(95%%) %.2f \u00B1(99%%)";
// This doesn't work '±' is replaced by '▒'
// System.out.println : 10.30 ▒(95%) 10.40 ▒(99%)
System.out.println(String.format(data, "System.out.println", 10.3, 10.4));
// This displays '±' correctly
// System.console().writer().println : 10.30 ±(95%) 10.40 ±(99%)
System.console().writer().println(String.format(data, "System.console().writer().println", 10.3, 10.4));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment