欢迎您 本站地址:  
返回首页   返回编程教学   一个都不能死  狗叫音效  DedeCMS模板源码  http状态码  课本点读  五代十国  新唐书  学习Chart.js 

Java getBytes() 方法

Java String类Java String类


getBytes() 方法有两种形式:

语法

public byte[] getBytes(String charsetName) throws UnsupportedEncodingException
或
public byte[] getBytes()

参数

返回值

返回 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类

小库提示

扫描下方二维码,访问手机版。