Java getBytes()
[Java String]Java String
getBytes()
getBytes(String charsetName): byte byte
getBytes(): byte byte
public byte[] getBytes(String charsetName) throws UnsupportedEncodingException public byte[] getBytes()
charsetName --
byte
import java.io.*;
public class Test {
public static void main(String args[]) {
String Str1 = new String("runoob");
try{
byte[] Str2 = Str1.getBytes();
System.out.println("" + Str2 );
Str2 = Str1.getBytes( "UTF-8" );
System.out.println("" + Str2 );
Str2 = Str1.getBytes( "ISO-8859-1" );
System.out.println("" + Str2 );
} catch ( UnsupportedEncodingException e){
System.out.println("");
}
}
}
[B@7852e922 [B@4e25154f [B@70dea4e
[Java String]Java String
Make a fortune
540***[email protected]
getBytes() byte[]
class Main { public static void main(String[] args) { String str = "make a fortune"; byte[] byt = str.getBytes(); for (byte b : byt) { System.out.println(b); } } }byte[] a byte[] 97
byte[]
Make a fortune
540***[email protected]