此方法使用平台的默认字符集将此String编码为字节序列,并将输出存储到新的字节数组中。
byte getBytes() - 语法
public byte[] getBytes()
byte getBytes() - 返回值
- 此方法返回输出字节数组。
byte getBytes() - 示例
import java.io.*; public class Test { public static void main(String args[]) { String Str1=new String("Welcome to Learnfk.com"); try { String Str2=new String( Str1.getBytes( "UTF-8" )); System.out.println("Returned Value " + Str2 ); Str2=new String (Str1.getBytes( "ISO-8859-1" )); System.out.println("Returned Value " + Str2 ); } catch ( UnsupportedEncodingException e) { System.out.println("Unsupported character set"); } } }
这将产生以下输出-
Returned Value Welcome to Learnfk.com Returned Value Welcome to Learnfk.com
参考链接
https://www.learnfk.com/java/java-string-getbytes.html
标签:Java,String,Str2,无涯,Value,byte,getBytes,Returned From: https://blog.51cto.com/u_14033984/8850855