Converting uXXXX Sequences Back with "-reverse" Option

This section provides a tutorial example on how to \uXXXX Unicode code sequences back to a native encoding like UTF-8 with the 'native2ascii -encoding utf-8 -reverse' command.



Warning: "native2ascii" has been discontinued since JDK 9. But if you still have JDK 1.8 installed, you can continue to use it to convert Java source from one encoding to another.

"native2ascii" also offers the "-reverse" option to help you convert text files with any \uXXXX Unicode code sequences back to any native encodings, like UTF-8, or GB2312.

The tutorial example below shows you how I converted some Chinese characters in a UTF-8 file to \uXXXX Unicode code sequences, then back to a GB2312 encoded file:

C:\herong>type HelloUtf8.java
/* HelloUtf8.java
 * Copyright (c) HerongYang.com. All Rights Reserved.
 */
public class HelloUtf8 {
   public static void main(String[] a) {
      System.out.println("Hello world!"); 	
      System.out.println("世界你好!"); 	
   }
}

C:\herong>\Progra~1\java\jdk1.8.0\bin\native2ascii -encoding utf-8 
   HelloUtf8.java HelloUtf8.unicode

C:\herong>type HelloUtf8.unicode
/* HelloUtf8.java
 * Copyright (c) HerongYang.com. All Rights Reserved.
 */
public class HelloUtf8 {
   public static void main(String[] a) {
      System.out.println("Hello world!");
      System.out.println("\u4e16\u754c\u4f60\u597d\uff01");
   }
}

C:\herong>\Progra~1\java\jdk1.8.0\bin\native2ascii -encoding gb2312 
   -reverse HelloUtf8.unicode HelloUtf8.gb2312

C:\herong>type HelloUtf8.gb2312
/* HelloUtf8.java
 * Copyright (c) HerongYang.com. All Rights Reserved.
 */
public class HelloUtf8 {
   public static void main(String[] a) {
      System.out.println("Hello world!");
      System.out.println("-++t-p¦+úí");
   }
}

As you can see, if you use "native2ascii" and "native2ascii -reverse" together, you can convert any non-ASCII file from one encoding to another encoding.



 

Table of Contents

 About This Book

 Java Tools Terminology

 Java Tools Included in JDK

 javac - The Java Program Compiler

 jar - The JAR File Tool

 jlink - The JRE Linker

 jmod - The JMOD File Tool

 jimage - The JIMAGE File Tool

 java - The Java Program Launcher

 jdeps - The Java Class Dependency Analyzer

 jdeprscan - The Java Deprecated API Scanner

 jdb - The Java Debugger

 jcmd - The JVM Diagnostic Tool

 jconsole - Java Monitoring and Management Console

 jstat - JVM Statistics Monitoring Tool

 JVM Troubleshooting Tools

 jhsdb - The Java HotSpot Debugger

 jvisualvm (Java VisualVM) - JVM Visual Tool

 jmc - Java Mission Control

 javap - The Java Class File Disassembler

 keytool - Public Key Certificate Tool

 jarsigner - JAR File Signer

 jshell - Java Language Shell

native2ascii - Native-to-ASCII Encoding Converter

 native2ascii - Encoding Converter Command and Options

 javac - Using CP1252 to Process Source File

 "native2ascii -encoding" - UTF-8 to uXXXX Conversion

 Setting UTF-8 Encoding in PrintStream

Converting uXXXX Sequences Back with "-reverse" Option

 Outdated Tutorials

 References

 Full Version in PDF/EPUB