Java provides a simple tool named native2ascii to convert native to ASCII and ASCII to native. Native characters are represented in ASCII using its Unicode equivalent. You can find the native2ascii tool in the JAVA_HOME/bin
To convert native to ascii you can use the below given command.
/local/opt/java/bin/native2ascii -encoding utf8 source-file target-file
source file should have native content. native2ascii tool will generate the ascii for the content and place it in the target file.
1 2 3 4 |
vi source-file (名) 2004年12月26日に起きた大津波, 地震の余波で2大陸8カ国(タイとインドとインドネシアとマレーシアとモルジブとセイシェルとソマリアとスリランカ)のおよそ22万5千人の命を奪った津波 (名) 津波, 地震や火山の噴火によっておこる高波(日本語) |
1 2 3 4 5 6 7 8 9 |
vi target-file (\u540d) 2004\u5e7412\u670826\u65e5\u306b\u8d77\u304d\u305f\u5927\u6d25\u6ce2, \u5730\u9707\u306e\u4f59\u6ce2\u30672\u5927\u96788\u30ab\u56fd\uff08\u30bf\u30a4\u3068\ u30a4\u30f3\u30c9\u3068\u30a4\u30f3\u30c9\u30cd\u30b7\u30a2\u3068\u30de\u30ec\u30fc\ u30b7\u30a2\u3068\u30e2\u30eb\u30b8\u30d6\u3068\u30bb\u30a4\u30b7\u30a7\u30eb\u3068\ u30bd\u30de\u30ea\u30a2\u3068\u30b9\u30ea\u30e9\u30f3\u30ab\uff09\u306e\u304a\u3088\ u305d22\u4e075\u5343\u4eba\u306e\u547d\u3092\u596a\u3063\u305f\u6d25\u6ce2 (\u540d) \u6d25\u6ce2, \u5730\u9707\u3084\u706b\u5c71\u306e\u5674\u706b\u306b\u3088\u3063\u3066\u304a\u3053\ u308b\u9ad8\u6ce2\uff08\u65e5\u672c\u8a9e\uff09 |
On the same way you can convert a ASCII file written in unicode to native using…
1 |
/local/opt/java/bin/native2ascii -reverse -encoding utf8 target-file source-file |
Pingback: How to convert native character to unicode and unicode to native? | Clean Java