Java's Chinese programming and configuration experience

zhaozj2021-02-16  50

Java's Chinese programming and configuration experience

Java's Chinese problem has a long history, and it has not been completely solved. However, there is a countermeasure under policies, we always have a way to get it. There are two main types of Chinese issues related to Java, one is programmed, involving I / O, internal code conversion, etc. The second category is the configuration of the Java operating environment, involving font, attribute configuration, etc. I just solved these problems a day, I think it is necessary to write a memo to myself. I still start with the problem, so that you don't let everyone sleep. I want to write a program, this program has a basic feature to display the file content, I use Jtextarea to do something displayed, the program is simple to home, but it is Chinese. My configuration is JBuilder7, JBuilder comes with JDK1.3.3_b24, my own JDK is JDK1.4.0_02_b02, all of the mainstream JDK. The operating system is English WINDOWS2000 plus Chinese support package. I try to change JDK, 1.3.3 and 1.4.0 can't, Down's latest J2SDK-1_4_1-RC is not, it is not a JDK problem, so I will concentrate on the I / O coding conversion, I check The article on the Java Chinese issue, clearing the encoded conversion, but how to try, change what the coding is not good, but it is even worse, and some rules are still a bit of chaos, that is, in the pure English system As shown, I don't know that Chinese characters, just show that I can't show it, I will become a question mark. Oh, depressed! Encoding Conversion Experience: Java is an unicode encoding. If you use Reader / Writer when I / O, you want to use system properties file.encoding as encoding. If you use stream, there is no change, it is binary data. Useful methods are: 1. Add Encoding options on Reader / Writer, pay attention to the direction of the encoding, encoding in Reader indicates that the data is converted from Encoding into Unicode, and Writer is converted to an Encoding format. 2. Use string.getbyte () to convert a string into a specified encoding. Common coding format: ISO8859_1, this is the default 8bit code of the English system, because it is 8bit, so it will not delete the high level of the Chinese characters, so it can also handle Chinese characters (I don't think so I don't think so I don't think it. Proper, but I don't know where I don't care, I still hope that the senior people pointed out). GB2312 and GBK, Chinese character encoding, recommended using GBK, it is compatible with GB2312 and supports more Chinese characters. Unicode, a big character set, I don't know if it is an international standard, I have supported it. I use 16 bits to each character encoding. Although the Chinese characters are right, but in English is losing, I have to use more space to store, so many People are still boring, and the written procedures do not support unicode. There are two kinds of solutions in the Chinese issue of JSP / servlet: 1.

Not encoded in the program, give this job to the browser, the method is to compile all Beans with javac -encoding gbk * .java, then add <% @ page contenttype = "on the JSP page. GB2312 "%" or directly plus in html: Try to know, I don't know clearly . 2. Specify the encoding in the program, compile all the beans with javac -encoding ISO8859_1 * .java, add str = new string on the program involving Chinese display (Str.GetBytes); the above two methods cannot be mixed , Means either GBK, or ISO8859_1, it is the same from the outside. The Chinese issue of database JDBC, generally converted according to the code specified by the database, for example, according to ISO8859_1 read, ISO8859_1 written, usually there is no problem. Although there are experiences on these codes, it does not solve my problem. It seems that my program input and output is ISO8859_1, my problem is nothing to do with the coding. Is it the problem of a font? In Swing components, the font is always then a few, basically dying, and the choice is not. But I suddenly discovered that the configuration of these fonts was font.properties, which generally jdk has a Chinese font profile, which may be Font.Properties.en, some of the different versions of JDK names, you want It is to override the Font.Properties file in Chinese configuration. I thought it was successful, but I fell ruthlessly again to fight me again. Not right, but in the Windows system, Java can more automatically check your system encoding, using the most suitable font profile, usually do not need to change, it is true to change before JDK1.2, No wonder that article is the documentation of JDK1.1. Even font.properties is not a spirit, oh, is there a problem with jbuilder? When I got here, I have to doubt it, although it never disappointed, I turned off JBuilder, pick up the JDK command line, oh! Cute Chinese is actually coming out! It's just ..... 莫 其, because JBuilder uses this JDK? No reason, I open JBuilder again, run, garbled! ... ....... I will take a look ..... I copied the execution command inside jbuilder to the DOS window ... There is no Chinese ..... Weird, I am carefully controlled me The command of the hand and JBuilder copied, except that Java uses Java, is almost the same, is it ....... this Java and Javaw will not be different? Oh ....... I want to say anything, the answer is this, JavaW will work with Java different local configuration, which has never been seen in Chinese, and Java is good.

转载请注明原文地址:https://www.9cbs.com/read-24982.html

New Post(0)