The java.lang.String.getBytes (string charsetname) method encodes this String using a sequence of bytes for the specified character set and stores the result in a new byte array.
Statement
The following is a declaration of the Java.lang.String.getBytes () method
Publicbyte[] getBytes(String charsetname)throws Unsupportedencodingexception
Parameters
return value
This method returns the resulting byte array.
Abnormal
Example
The following example shows the use of the Java.lang.String.getBytes () method.
PackageCom.Yiibai;ImportJava.Lang.*;Public Class Stringdemo { Public Static voidMain(String[]Args) Throws Exception { String with numbers and some special characters StringStr= "[Email protected]"; byte array with CharSet ByteBval[] =Str.GetBytes("UTF8"); Prints the byte array for (int I = 0; I < Bval.; I++) { system.. Printlnbval[i } }}
Let's compile and run the above program, which will produce the following results:
A .
Java.lang.String.getBytes (String CharsetName) Method instance