Java 用于编码 ASCII 的不可映射字符,但我的文件是 UTF-8

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26067350/
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-08-11 01:47:31  来源:igfitidea点击:

Unmappable character for encoding ASCII but my files are in UTF-8

javaencodingutf-8ascii

提问by Jerome Ansia

I have the following error launching my ant script:

启动我的 ant 脚本时出现以下错误:

[javac] /****/TextUtils.java:25: error: unmappable character for encoding ASCII

But this file is encoded in UTF-8, if i do the info command:

但是这个文件是用 UTF-8 编码的,如果我执行 info 命令:

/***/TextUtils.java: text/plain; charset=utf-8

Why is this file compiled in ASCII and not in utf-8?

为什么这个文件是用 ASCII 而不是 utf-8 编译的?

I tried to force the encoding in utf-8 on the javac command in my ant build file but without success

我试图在我的 ant 构建文件中的 javac 命令上强制使用 utf-8 编码,但没有成功

采纳答案by Alexey Semenyuk

Setting the Default Java File Encoding to UTF-8:

export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8

将默认 Java 文件编码设置为 UTF-8:

导出 JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8

From ant: warning: unmappable character for encoding UTF8

来自蚂蚁:警告:用于编码 UTF8 的不可映射字符