java 关于编码 UTF-8 的不可映射字符的编译错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4242722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 05:28:09  来源:igfitidea点击:

compilation error regarding unmappable character for encoding UTF-8

java

提问by user339108

  //  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?

我在我的 java 代码中注释掉了上面的代码,但是我得到了“用于编码 UTF-8 的不可映射字符”。我该如何解决?

回答by OmnipotentEntity

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

您需要使用 -encoding 标志在 javac 命令行中指定编码

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.

您还可以考虑将 UTF-8 设为您的系统默认编码,这样您就不必指定它了。

回答by Gilberto

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):

ISO-8859-1 中的大量 java 文件也有同样的编译器错误。一一打开是行不通的。所以,这是一个快速修复(使用 recode):

find -name '*.java' -exec recode Latin-1..UTF-8 {} \;