简体   繁体   English

Intellij IDEA:“用于编码 UTF-8 的不可映射字符”编译 ISO-8859-1 文件

[英]Intellij IDEA: “unmappable character for encoding UTF-8” compiling ISO-8859-1 files

I have a mixed-encoding source tree and I'm getting the warning above for some of my source files.我有一个混合编码的源代码树,并且我的一些源文件收到了上面的警告。 I managed to sucessfully set the encoding for those files to ISO 8859-1 and, after invalidating IDEA's caches, they now display correctly in the editor.我成功地将这些文件的编码设置为 ISO 8859-1,并且在使 IDEA 的缓存无效后,它们现在可以在编辑器中正确显示。 However, when I compile, I still get the error message.但是,当我编译时,我仍然收到错误消息。

Production builds use ant and it's not an issue there, but it means I can't "make" in the IDE.生产版本使用 ant,这不是问题,但这意味着我无法在 IDE 中“制作”。 Is there a way to get IDEA to compile these correctly, or failing that, drop the error down to a warning?有没有办法让 IDEA 正确编译这些,或者失败了,将错误降为警告?

I solved this issue adding this property in IntelliJ option panel Compiler/Java Compiler :我解决了这个问题,在 IntelliJ 选项面板Compiler/Java Compiler 中添加了这个属性:

Additional command line parameters : -encoding ISO-8859-1附加命令行参数-encoding ISO-8859-1

I have UTF-8 encoding in encoding.xml as follows, but still not working.我在 encoding.xml 中有如下 UTF-8 编码,但仍然无法正常工作。 keeps getting error "Error: java: error: unmappable character (0xFE) for encoding UTF-8"不断收到错误“错误:java:错误:编码UTF-8的不可映射字符(0xFE)”

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
    <file url="file://$PROJECT_DIR$" charset="UTF-8" />
    <file url="PROJECT" charset="UTF-8" />
  </component>
</project>

看起来像一个已知的错误

If you are using Intellij, the fastest way for me was:如果您使用的是 Intellij,对我来说最快的方法是:

File -> File Properties-> File encoding

and choose the one you want, in this case ISO-8859-1 .并选择您想要的,在本例中为ISO-8859-1

Solution tested in IntelliJ 2019.3在 IntelliJ 2019.3 中测试的解决方案

Open the troublesome file.打开麻烦的文件。 Go to File -> File Encoding.转到文件 -> 文件编码。 ( You also have a quick option at the bottom right ) Select the encoding you want. 右下角还有一个快速选项)选择所需的编码。 In my case it was UTF-8.就我而言,它是 UTF-8。 Click on Convert when it prompts you if you want to convert the file in new encoding and overwrite the contents.当它提示您是否要以新编码转换文件并覆盖内容时,单击转换。

Try to compile.尝试编译。 You should be able to compile fine.你应该能够很好地编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM