Java Chinese programming and configuration experience

Source: Internet
Author: User
Tags character set
Java has a long history in Chinese, and it has never been completely solved yet. However, there are policies and countermeasures that we can always solve. There are two main types of Chinese problems related to Java: Programming issues, I/O and internal code conversion. The second type is the configuration of the Java Runtime Environment, involving the font and attribute configuration. I spent just one day solving these problems and felt it was necessary to write a memorandum for myself.
I think we should start with the problem. This will not let everyone sleep. I want to write a program. The basic function of this program is to display the file content. I use JTextArea to do the display. The program is simple, but Chinese characters are garbled. My configuration is JBuilder7 and JBuilder comes with JDK1.3.3 _ b24. My own JDK is JDK1.4.0 _ 02_b02, which is the mainstream JDK. The operating system is an English Windows Plus Chinese support package.
I try to change JDK, 1.3.3 and 1.4.0 are not good, down a latest j2sdk-1_4_1-rc is not good, it seems not JDK problem, so I focus on the I/O encoding conversion, I read a number of articles on JAVA Chinese on the Internet, and I made it clearer about encoding conversion. But how can I try it? I can't do anything about encoding, but it shows worse, at the beginning, I still had some messy rules, as shown in the English-only system. I still know that it is a Chinese character, but it cannot be displayed. I will wait for the encoding, it becomes a question mark. Alas, depressed!
Coding conversion experience:
JAVA uses UNICODE encoding internally. If Reader/Writer is used in I/O, encoding conversion is required. The system attribute file. encoding is used as the encoding method. If Stream is used, there will be no conversion. It is Binary data.
The following are useful methods: 1. Add the encoding option to Reader/Writer. Pay attention to the encoding direction. encoding in Reader indicates converting data from encoding to Unicode. writer converts Unicode characters to encoding format. 2. Use String. getByte () to convert the String to the specified encoding.
Common encoding format: ISO8859_1, which is the default 8-bit encoding in the English system. Because it is 8-bit, it will not delete the high positions of Chinese characters, therefore, it can also be used to process Chinese characters. (I think it is inappropriate, but I don't know where it is. I still hope you can point it out ). GB2312, GBK, and Chinese character encoding are recommended. It is compatible with GB2312 and supports more Chinese characters. UNICODE, a large character set. I wonder if it is supported by international standards. It uses 16-bit encoding for each character. Although Chinese characters are suitable, English is compromised, it takes more than twice the storage space, so many people are reluctant to write programs that do not support UNICODE.
There are two solutions to the Chinese issue of JSP/Servlet: 1. If you do not perform code conversion in the program, submit the job to the browser by using javac? Cencoding GBK *. java to compile all beans, and then add

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: info-contact@alibabacloud.com 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.