Last active
August 29, 2015 14:11
-
-
Save mattwarren/b560a8e1de010cfdac00 to your computer and use it in GitHub Desktop.
Console Demo showing Windows Console Encoding Issues with '±'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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