17

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.*;
        ^
Saurabh Vemuri
  • 181
  • 1
  • 1
  • 6

6 Answers6

19

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
Sunny Patel
  • 7,830
  • 2
  • 31
  • 46
14

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

Sajin Pattath
  • 241
  • 3
  • 5
11

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.

sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40
Jeff
  • 125
  • 3
  • 9
  • 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. – Lonzak Jun 06 '21 at 20:45
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

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.

jeet.chanchawat
  • 5,842
  • 5
  • 38
  • 59
0

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