Convert string to UTF8 bytes in Java
Description
The following code shows how to convert string to UTF8 bytes.
Example
/*from w ww.j a v a 2 s . c om*/
public class Main {
public static void main(String args[]) throws Exception {
String s = "0123456789";
byte ptext[] = s.getBytes("UTF8");
for (int i = 0; i < ptext.length; i++) {
System.out.print(ptext[i] + ",");
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »