Java – Convert Chinese character to Unicode with native2ascii

The native2ascii is a handy tool build-in in the JDK, which is used to convert a file with ‘non-Latin 1’ or ‘non-Unicode’ characters to ‘Unicode-encoded’ characters.

Native2ascii example

1. Create a file (source.txt)

Create a file named “source.txt”, put some Chinese characters inside, and save it as “UTF-8” format.

2. native2ascii

Use native2ascii command to convert it into Unicode format.


C:\>native2ascii -encoding utf8 c:\source.txt c:\output.txt

The native2ascii will read all the characters from “c:\source.txt” and encode it with “utf8” format, and output all encoded characters to “c:\output.txt”

3. Read Output

Open the “c:\output.txt”, you will see the all encoded characters, e.g \ufeff\u6768\u6728\u91d1

Reference

1. http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/native2ascii.html

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
9 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
4 Comment authors
bboynam99rlunarorameshwarDebananda PadhiJSF 2 internationalization example Recent comment authors
newest oldest most voted
bboynam99
Guest
bboynam99

I have some chinese documents with u9648u5706u5706 things….,how can i convert them back chinese please???

rlunaro
Guest
rlunaro

hello, I’m afraid that the link is not working anymore. The correct link should be:

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/native2ascii.html

rameshwar
Guest
rameshwar

nice explaination its very good

Debananda Padhi
Guest
Debananda Padhi

please attach the complete code in jave SE6 to use unicode conversion using UTF-8 for oriya i.e., type oriya using ascii keyboard and it will display in oriya character

trackback
JSF 2 internationalization example

[…] JSF 2.0 Note For UTF-8 or non-English characters, for example Chinese , you should encode it with native2ascii […]

trackback
Struts 2 – i18n or localization example

[…] 2. Properties file Make sure the properties file are named as country specified code. In some “non-Europe” or “non-English” like characters, you should always encode the content with native2ascii tool. […]

trackback
Struts 2 Chinese localization issue
trackback
Spring – resource bundle with ResourceBundleMessageSource example | Spring

[…] you have to use “native2ascii” tool to convert the Chinese characters to Unicode characters in order to display it […]

trackback
Spring MVC internationalization example

[…] Spring MVC Note For UTF-8 or non-English characters , it have to encode with native2ascii […]