Solution to non- able characters encoded in GBK

Source: Internet
Author: User

This is because: JDK is an international version. If we do not use the-encoding parameter to specify our Java source during compilationProgramJavac.exe first obtains the default encoding format used by the operating system, that is, when compiling a Java program, if we do not specify the encoding format of the source program file, JDK first obtains the file of the operating system. the encoding parameter (which stores the default encoding format of the operating system, such as Win2k, whose value is GBK). Then, JDK extracts our Java source program from file. the encoding format is converted to the Java internal default Unicode format and placed into the memory. Then, javac compiles the converted unicode format file. class file. the class file is unicode encoded and is temporarily stored in the memory. Then, JDK saves the compiled class file encoded with Unicode to our operating system to form what we see. class file. For us, what we finally get. A class file is a class file whose content is saved in Unicode encoding format. It contains a Chinese character string in our source program, but it has been written by file. the encoding format is converted to the unicode format. When we compile without setting it, it is equivalent to using the parameter javac-encoding gbk xx. Java, of course there will be incompatibility.


<Javac destdir = "$ {build. dir}/classes" DEBUG = "true" deprecation = "false" optimize = "false" failonerror = "true" Encoding = "UTF-8">
<SRC Path = "$ {SRC. dir}"/>
<Classpath refID = "classpath"/>

Add the encoding parameter to javac.EncodingMethod is actualEncodingYou can.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.