Java getBytes () -Methode
Es gibt zwei Formen getBytes () Methode:
getBytes (String charsetName): mit den Standardzeichensatz - String-Plattform als Byte - Sequenz kodiert wird , um das Ergebnis in ein neues Byte - Array zu speichern.
getBytes (): der Plattform unter Verwendung von Standard - Zeichensatz - String als Byte - Sequenz kodiert wird , um das Ergebnis in ein neues Byte - Array zu speichern.
Grammatik
public byte[] getBytes(String charsetName) throws UnsupportedEncodingException 或 public byte[] getBytes()
Parameter
charsetName - unterstützten Zeichennamen.
Rückgabewert
Gibt die Byte-Array.
Beispiele
import java.io.*; public class Test { public static void main(String args[]) { String Str1 = new String("w3big"); 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("不支持的字符集"); } } }
Die oben genannten Programmausführung Ergebnisse:
返回值:[B@7852e922 返回值:[B@4e25154f 返回值:[B@70dea4e