Im trying to compile the '§' character into a char (char c = '§'
) but when i try to build, it says in the build output "Unclosed character literal
" and "Illegal character: '\u00a7'
" followed by "Unclosed character literal
" again. If i put the character into a String (String s = "§"
) it works fine. But when i print it to console, it prints the 'Â' character (which it shouldn't)
In another java project, i can use the '§' character fine and compile normally, and it works as intended; printing it to console shows nothing (which is normal, because it's used as an escape character for colouring the text). That project (and the current one) don't use "BOM" in intellij, and they both use UTF8 encoding
Does anyone know how to fix this? thanks:)
How I could reproduce that error:
Test.java
with UTF-8 encoding (default)char c = '§';
and print itTest.main()
no errors, as expected.
So I tried:
Test1.java
and changed to ISO-8859-1
encodingTest1.java
this time I got the reported error but for Test.java
(still encoded as UTF-8)
Looks like IDEA uses the encoding of first file for the whole source code.
Solutions: