Java encoding of source file with Chinese character

I am importing a Java project from a Windows platform into Ubuntu.
My Ubuntu - 10.10, Gnome: My LANGUAGE environment is set to en_US:en
My terminal character encoding: Unicode (UTF-8)
My IDE is encoding an eclipse and a text file: GBK.

There is some Chinese constant character in the source file.

Project success on Windows with ant,
but on Ubuntu I get a compilation error:

  illegal character: \ 65533 

I don’t want to use the \ uxxxx format, since the file already exists,

And I tried the -encoding for javac, but still can't compile.

+4
source share
3 answers

I think the problem is not with Ubuntu, the Ubuntu console, Javac or Eclipse, but with the way you transfer the file from Windows to Ubuntu. You must save it as utf-8 before copying it to Ubuntu, otherwise the code point information installed on Windows, your locale is already lost.

0
source

Have you specified the encoding <javac> task option in your build.xml ?

It should look like this:

 <javac encoding="GBK" ...> 

If you did not specify it, then on Windows it will use the default encoding for the platform (which is GBK in your setup), and on Linux it will use the standard encoding of the platform (which is UTF-8 in your setup).

Since you want the assembly to work on both platforms (preferably without changing the configuration of any platform), you need to specify the encoding at compilation.

0
source

You need to convert the source code from the Windows codepage to UTF-8. Use iconv for this.

-1
source

Source: https://habr.com/ru/post/1343157/


All Articles