Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compilation error regarding unmappable character for encoding UTF-8

Tags:

java

  //  Fahrenheit (°F)

I have the above code commented out in my java code, but I get the "unmappable character for encoding UTF-8". How do I fix this?

like image 697
user339108 Avatar asked Jan 21 '23 01:01

user339108


2 Answers

You need to specify the encoding in your javac command line using the -encoding flag

javac -encoding UTF-8 myclass.java

You can also look into making UTF-8 your system default encoding so you don't have to specify it.

like image 158
OmnipotentEntity Avatar answered Jan 23 '23 14:01

OmnipotentEntity


Having this same compiler error with a ton of java files in the ISO-8859-1. Opening one by one is impracticable. So, here's a quick fix (using recode):

find -name '*.java' -exec recode Latin-1..UTF-8 {} \;
like image 27
Gilberto Avatar answered Jan 23 '23 14:01

Gilberto