Reputation: 558
Context: Windows 10, cmd.exe, javac 9.0.1.
I have unicode encoded source code. If I run javac -encoding UTF-8 ...
and I have an error, I just can't get it to display the source correctly.
As you can see in the picture, the cli can print unicode chars just fine.
Upvotes: 2
Views: 1015
Reputation: 140318
It would appear that javac is not using your terminal's character encoding.
You can specify the character encoding for a JVM using the flag:
java -Dfile.encoding=UTF-8 ...
(Or whatever encoding)
Javac is just a thin wrapper around a Java program. You can pass arguments directly to its JVM using the -J
flag. So:
javac -J-Dfile.encoding=UTF-8 ...
Upvotes: 5
Reputation: 2228
You can know your current(default) encoding by running
System.getProperty("file.encoding")
and you can change default encoding with this property.
For Windows it is usually - cp1252
,
Long Story, queue from IBM KB:
Internally, the Java virtual machine (JVM) always operates with data in Unicode. However, all data transferred into or out of the JVM is in a format matching the file.encoding property. Data read into the JVM is converted from file.encoding to Unicode and data sent out of the JVM is converted from Unicode to file.encoding.
Upvotes: 0