Incorrect console encoding under Windows 11 [message #1853044] |
Wed, 15 June 2022 15:44 |
Ulrich Schmidt Messages: 1 Registered: June 2022 |
Junior Member |
|
|
Hello,
when using JDK-18 from Oracle with "Text file encoding" set to default (UTF-8) the following code
import java.nio.charset.*;
public class ABC {
public static void main(String[] args) {
System.out.println(Charset.defaultCharset());
System.out.println(System.console());
System.out.println(System.out.charset());
System.out.println("äöü߀");
}
}
generates the following output
UTF-8
null
windows-1252
���߀
which is clearly incorrect. The documentation of System.out specifies
Quote:
The encoding used in the conversion from characters to bytes is equivalent to Console.charset() if the Console exists, Charset.defaultCharset() otherwise.
but as the example shows the default character set is not used for console encoding.
Is this a bug? If so, is there a work-around?
|
|
|
Powered by
FUDForum. Page generated in 0.03111 seconds