Convert from Unicode to UTF-8 in Java
Description
The following code shows how to convert from Unicode to UTF-8.
Example
//from w w w. j a v a 2 s. c o m
import java.util.Arrays;
public class Main {
public static void main(String[] argv) throws Exception {
String string = "abc\u5639\u563b";
byte[] utf8 = string.getBytes("UTF-8");
System.out.println(Arrays.toString(utf8));
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »