Last active
August 29, 2015 14:03
-
-
Save sebgod/9aa655d75e287d9d7e00 to your computer and use it in GitHub Desktop.
Testing UTF-8 as a default output for Windows
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
class Hello { | |
public static boolean ensureEncodingToUTF8() { | |
String osEncoding = System.getProperty("file.encoding"); | |
if (!osEncoding.equals("UTF-8") || !osEncoding.equals("UTF8")) { | |
java.lang.System.setProperty("file.encoding", "UTF-8"); | |
try { | |
System.setOut(new java.io.PrintStream(System.out, true, "UTF-8")); | |
} catch (Exception inner) { | |
return false; | |
} | |
} | |
return true; | |
} | |
public static void main(String[] args) { | |
ensureEncodingToUTF8(); | |
System.out.println("你好世界!"); | |
} | |
} |
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
javac -J-Dfile.encoding=UTF-8 Hello.java && jar cvfe hello.jar Hello Hello.class && jar i hello.jar && java -jar hello.jar |
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
#!/bin/sh | |
javac Hello.java && jar cvfe hello.jar Hello Hello.class && jar i hello.jar && java -jar hello.jar |
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
class UnicodePrintStream extends java.io.PrintStream { | |
public UnicodePrintStream(java.io.OutputStream orig, | |
java.nio.charset.Charset charset) | |
throws java.io.UnsupportedEncodingException { | |
super(orig, true, charset.name()); | |
} | |
public java.io.OutputStream getOriginalStream() { | |
return out; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment