Java will use Chinese characters into Unicode encoding
This two-day operation to the use of XML Jdom, in the creation of the XML file and output to the hard drive when the Chinese encountered a coding problem: Jdom default output of XML encoding is UTF-8, but the document if Chinese characters then the Chinese characters it will become garbled, resulting XML document can not be the correct analysis.
UTF -8 can be used to be said that the Chinese? I do not know if this is not a Jdom BUG (Jdom 1.0, beta, the product of 10!). I had to google, we solution to the problem is to make the output of Character Set Jdom to GBK or GB2312, but it will have some side effects, if there is no specific Character Set (GBK or GB2312), the operating system still is not Analytical not correct? A better solution is first converted into Unicode encoding Chinese in direct output, XML analytical procedures after the time back then encoded Unicode Chinese will be no problem.
So I read the JDK documents, as Java 5 do not seem to have a similar type of conversion can be used directly, but I found a category java.util.Properties, its source code, there are two private (private) methods loadConvert ( char in [], int off, int len, char [] convtBuf) and saveConvert (String theString, boolean escapeSpace) is actually doing special characters and switch between Unicode character encoding, I extracted from them, to a separate category in the packaging can be used.
Below are the categories I CharacterSetToolkit.java packaging, if you use in the project please do not change the package, such as the author and author information.
Http://download1.csdn.net/down3/20070517/17112419560.zip
Tags: java Chinese, java encoding, java unicode






