1. Convert Chinese characters to Unicode:
c:\ Program Files \ Java \ JDK 1 . 5 . 0 _ 04 \ bin & gt; native2ascii
test
\u6d4b\u8bd5
2. Convert Unicode into Chinese characters:
c:\ Program Files \ Java \ JDK 1 . 5 . 0 _ 04 \ bin & gt; Native 2 ascii- reverse
\u6d4b\u8bd5
test
Native2ascii.exe, which comes with java, is a good transcoding tool, which is in the bin directory. If you have Chinese characters in your properties, you need to convert them to unicode. Then copy the attributes containing Chinese characters to the bin directory, and then enter the bin directory in cmd, and enter: Native 2 ascii- encoded UTF-8 language-ext _ zh _ cn.properties.native language-ext _ zh _ cn.properties. Language-ext_zh_CN.properties is a transcoded file.
When doing Java development, there are often some garbled words or files that cannot be correctly recognized or read, such as the public message resource (attribute) file used by validator, which needs to be recoded by Unicode. The reason is that java's default encoding method is Unicode, and our computer system encoding is often GBK and other encoding. It solves the problem of converting the coding of the system into the coding that java can correctly recognize.
Introduction to 1 and native2ascii: native2ascii is a tool provided by sun java sdk. Used to encode other text files (such as *. txt,*。 ini,*。 Property, *. Java, etc. ) to Unicode encoding. Why do you need transcoding? The reason lies in the internationalization of the program. Definition of Unicode Coding: Unicode (Uniform Code, Universal Code, Single Code) is a character coding used in computers. It sets a unified and unique binary code for each character in each language to meet the requirements of cross-language and cross-platform text conversion and processing. 1990 started research and development, and 1994 was officially announced. With the enhancement of computer working ability, Unicode has been popularized in the past ten years. (Declaration: Unicode encoding definition comes from the Internet).
2.Get native2ascii: After installing the jdk, if it is installed on windows, there will be a bin directory under the jdk installation directory, in which native2ascii.exe happens to be.
3.native2ascii command line naming format:
Native 2 ascii-[ options] [input file [output file]]
Description:
-[Option]: indicates the command switch, and there are two options to choose from.
-reverse: Convert Unicode encoding to local encoding or specify encoding, otherwise it will be converted to local encoding.
-encoding encoding_name: Converts to the specified encoding, and encoding_name is the encoding name.
[input file [output file]]
Inputfile: indicates the full name of the input file.
Outputfile: output file name. If this parameter is missing, it will be output to the console.
4. Best practice: First, add the bin directory of JDK to the system variable path. Create a test directory under the disk, create a zh.txt file under the test directory, the file content is "Lava", open the "command prompt" and enter the C:\test directory. You can follow the instructions step by step and pay attention to the change of coding.
A: convert zh.txt into Unicode code and output the file to u.txt
native2ascii zh.txt u.txt
Open u.txt, which says "\u7 194\u5ca9".
B: convert zh.txt into Unicode code and output it to the console.
c:\ test & gt; native2ascii zh.txt
\u7 194\u5ca9
As you can see, the console outputs "\u7 194\u5ca9".
C: convert zh.txt into ISO8859- 1 code, and output the file to i.txt
Native2ascii encoding iso8859-1zh.txti.txt.
Open the i.txt file with the content "\ u00c8 \ u00db \ u00d1\ u00d2".
D: convert u.txt into local code and output it to the file u _ NV.txt
native 2 ascii-reverse u . txt u _ NV . txt
Open the u_nv.txt file, and the content is "Lava".
E: convert u.txt into local code and output it to the console.
c:\ test & gt; native2ascii -reverse u.txt
volcanic rock
As you can see, the console outputs "lava".
F: convert i.txt into local code and output it to i _ nv.txt
Native 2 ascii- reverse i.txt i_nv.txt
Open the file i_nv.txt, which reads "\ u00c8 \ u00db \ u00d1\ u00d2". It is found that it is exactly the same before and after transcoding. In other words, it is equal to not turning around, or being confused and not knowing the name. .
G: convert i.txt into GBK code and output it to i _ gbk.txt
Native 2 ascii- reverse encoding GBK i.txt i_gbk.txt
Open the file i_gbk.txt, which reads "\ u00c8 \ u00db \ u00d1\ u00d2". It is found that it is exactly the same before and after transcoding. In other words, it is equal to not turning around, or being confused and not knowing the name.
H: transcode u_nv.txt into local code GBK and output it to the console.
c:\ test & gt; Native 2 ascii- reverse coding ISO8859- 1 i.txt
volcanic rock
Judging from this result, the goal has been achieved. The encoding of i.txt is ISO8859- 1, and the content is "lava" after being converted into local encoding. It should be recognized from this that the encoding specified by -encoding in the native2ascii -reverse command is the encoding format of the source file. The encoding specified by -encoding in the native2ascii command is the encoding format of the (generated) target file. This is very important! Remember! !
Continue to explore and create a new file 12a.txt, with the content of "12axyz". Let's see what happens with pure alphanumeric coding.
I: Convert the pure alphanumeric text file 12a.txt into Unicode encoding.
native 2 ascii 12a . txt 12a _ NV . txt
Open the file 12a_nv.txt with the content "12axyz".
Continue testing and switch to ISO8859- 1 code.
c:\ test & gt; The local ascii code is iso8859-112a.txt.
12 XYZ
The result is still no transcoding.
From the results, it can be concluded that for text types of pure numbers and letters, the content before and after transcoding is the same.