java: Solve the error reporting illegal characters: '\ufeff' and what is BOM

background

After running the JAVA project, the error message: 非法字符: '\ufeff', as shown in the figure:
insert image description here
But I did not find this character in the file that reported the error, what is the reason?

what is BOM

BOM (Byte Order Mark), a hidden character, byte order mark, appears in the header of a text file to identify which format the file is encoded in.

Similar to Windows' built-in Notepad and other software, when saving a UTF-8 encoded file, three invisible characters (0xEF 0xBB 0xBF, namely BOM) will be inserted at the beginning of the file. It is a string of hidden characters used to allow editors such as Notepad to recognize whether this file is encoded in UTF-8. For normal files, this doesn't cause any trouble. But for PHP, JAVA, etc., it will be recognized as illegal characters.

Editors under Linux should not have this problem. Under WINDOWS, do not use editors such as Notepad.

solve

Select the file that reported the error, click UTF-8 in the lower right corner of IDEA, and then click Remove BOM, and you can
insert image description here
disable it when setting the global

insert image description here

Guess you like

Origin blog.csdn.net/weixin_43972437/article/details/132089884