How To Convert East-Asian Character To Unicode In Java

East-Asian character ( Chinese, Japanese, Korean ) is different from western character. But our web application should be accessed from all over the world. So we should support display those east-asian characters in web page correctly. The solution to resolve character charset issue is to use unicode for all languages messages in our web application. So we need to convert the character to unicode before render them to client web page.

Java provide native2ascii command to implement this goal, and eclipse also has native2ascii plugin that can make the unicode converter. If you develop web application with spring tool suite, it has integrate the native2ascii plugin by default, this article will tell you how to use above tool to convert east-asian character to unicode in java.

1. Use native2ascii Tool To Convert Character To Unicode.

  1. Save original Chinese words ( 今天天气很好 ) in a file chinese.txt.
  2. Open a terminal and run native2ascii command. The first argument is the source text file which contains Chinese words, the second argument is the target unicode character file which will be generated. You should make sure your JDK has been installed correctly, and JAVA_HOME/bin folder has been added in the system PATH environment variable value for Windows OS.
    192:~ $ native2ascii chinese.txt
  3. Open the generated text file, you can find below unicode content.

2. Use Eclipse native2ascii Plugin.

There is a eclipse plugin which can help you to convert Chinese words to unicode directly when you input the words in a .properties file. Follow below steps to install it.

  1. Open eclipse, click Help —> Eclipse Market Place menu item.
    help eclipse marketplace menu item
  2. Input native2ascii after Find text box, click Go to search. Then click Install button to install it.
    search and install native2ascii eclipse plugin
  3. After install, you can create a file in the java project. Now when you input Chinese, Japanese or Korean words, it will be converted to unicode automatically.
  4. If you use Spring Tool Suite to develop spring web application, it has contains the native2ascii plugin already.
0 0 votes
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x