错误:非法字符:Java 中的“\ufeff”

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

error: illegal character: '\ufeff' in java

javacompilationubuntu-16.04

提问by Saurabh Vemuri

Got this error when compiled java code in ubuntu.

在 ubuntu 中编译 java 代码时出现此错误。

Got this error

得到这个错误

error: illegal character: '\ufeff'
import java.net.*;
^

error: class, interface, or enum expected
import java.net.*;
        ^
error: illegal character: '\ufeff'
import java.net.*;
^

error: class, interface, or enum expected
import java.net.*;
        ^

回答by Sunny Patel

As Jim Garrisonpointed out, you probably have a Byte Order Marker (BOM)at the start of the file. Use an editor that can view all non-printable characters and remove it.

正如Jim Garrison指出的那样,您可能在文件的开头有一个字节顺序标记 (BOM)。使用可以查看所有不可打印字符并将其删除的编辑器。

Alternatively, you can use sedto remove it:

或者,您可以使用sed将其删除:

sed '1s/^.//' infile >> outfile

回答by METEHAN KARA

Use another editor because it seems to be an eclipse UTF-8-BOM problem. Convert the UTF type UTF-8.

使用另一个编辑器,因为它似乎是 Eclipse UTF-8-BOM 问题。将 UTF 类型转换为 UTF-8。

And also I note that ; First it doesn't work for me and I convert the type ANSI and after convert type to UTF-8 format. It can be a another alternative solution for you

我还注意到;首先它对我不起作用,我将类型转换为 ANSI,然后将类型转换为 UTF-8 格式。它可以是您的另一种替代解决方案