error: illegal character: '\ufeff' in java
Asked Answered
C

8

21

Got this error when compiled java code in ubuntu.

![Got this error][1]

error: illegal character: '\ufeff'
import java.net.*;
^
error: class, interface, or enum expected
import java.net.*;
        ^
Chinoiserie answered 15/8, 2017 at 17:1 Comment(3)
Looks like a UTF-8 BOM (Byte Order Marker) at the start of the file. That should not be there, just remove it.Practically
How to remove that ?Chinoiserie
How did you create the file? Use an editor that does not add the BOM, or configure your editor to not add the BOM when editing UTF-8Practically
B
20

As Jim Garrison pointed 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.

Alternatively, you can use sed to remove it:

sed '1s/^.//' infile >> outfile
Bucharest answered 15/8, 2017 at 17:23 Comment(3)
Or in vim :set nobomb :wqAlmena
:x is shorter than :wq. :)Bucharest
if you use intellij right click on file and choose "Remove BOM"Judaea
F
19

If you are using IntelliJ, right click on the class file and select 'Remove BOM'. That should remove the BOM at the start.

Fatwitted answered 4/5, 2021 at 8:18 Comment(3)
It's strange but sometimes it doesn't work at first so I have first to add BOM and then remove BOMStage
Had the same issue with netlify.toml causing a config parsing error on Netlify. This worked, thanks.Ifni
This is present in the version of the IDE I am currently using under: File -> File Properties -> Remove BOM. IntelliJ version: 242.20224.300 on Mac.Vins
V
12

In case your are working on Windows O.S. and use Eclipse (which don't have the functionality to remove the BOM from the file), just open the file in Notepad++ and in the encoding menu, select "UTF-8", then save the file.

Vaginismus answered 14/8, 2020 at 8:34 Comment(1)
It is quite possible in eclipse: Just change the encoding of the file to iso (Right click on file - > Properties) and delete the first three BOM characters, save file and reopen it.Greathearted
C
3

If you use Intellij by following tools you can remove this error:

enter image description here

Calefacient answered 16/4 at 2:25 Comment(0)
L
2

I am using clean and modern looking UI in intellij, I removed BOM by clicking on the bottom right encoding which in my case was UTF-8, and a panel displaying the file encoding list appears, allowing me to easily choose the remove BOM option and proceed with the removal.

Liable answered 6/12, 2023 at 6:3 Comment(0)
P
1

IF you get java: illegal character: '\ufeff' error in java you must remove BOM on the right bottom of IDE Look bottom and right, click UTF-8 and remove BOM click for image

Pavis answered 15/6, 2023 at 5:47 Comment(0)
D
0

Use another editor because it seems to be an eclipse UTF-8-BOM problem. Convert the UTF type 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

Doha answered 5/3, 2019 at 14:32 Comment(0)
E
0

downloading models from https://codebeautify.org/json-to-java-converter is causing such problems.

create new file and copy/paste all data from the downloaded file.

Edea answered 21/4, 2021 at 11:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.