I am trying to print Hebrew characters from a Kotlin program (running on the console).
All the Hebrew characters are being output as question marks.
I created the following simple test.kts
script file for testing:
println("שלום מקוטלין")
// Try to print a simple non-Hebrew character too
println("\u0394") // Greek Delta
The file is properly saved in UTF-8 format.
It prints:
???? ???????
?
I tried running it in Command Prompt, PowerShell (both in its native window and in Windows Terminal), and Git Bash, all of which give the same result. I also tried redirecting the output to a file to rule out display issues in the shells.
To make sure the problem isn't the console itself, I also made simple test.bat
, test.ps1
, and test.sh
files with the following content:
echo "שלום מקוטלין"
All three shells correctly displayed the Hebrew text here, indicating that the problem is in Kotlin's output, not in the shell display. (Though PowerShell requires the file to be saved "UTF-8 with BOM" to display properly, this can't be the issue with Kotlin since Kotlin won't even run a script that is saved with a BOM.)
As far as I can tell, Kotlin should support UTF-8 output by default with no configuration needed.
How can I get the proper output?
Updates:
If I write the output to a file using java.io.File("out.txt").writeText("שלום מקוטלין")
, it works properly.
Also, if I open a new PrintStream
using val out = java.io.PrintStream(System.out, true, "UTF-8")
and then write to it using out.println("שלום מקוטלין")
, that works properly too.
Only writing to the console with println
is broken.
System info:
- Windows 10 2004 (Build 19041.450)
- Kotlin 1.4.0 (downloaded from GitHub Releases)
- Tested with
JAVA_HOME
pointing to both JRE 1.8.0_261 (Oracle) and 11.0.2 (Oracle OpenJDK).