zoukankan      html  css  js  c++  java
  • String 和 byte[]

    使用默认字符集合

    Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array. 

    public byte[] getBytes()

    Constructs a new String by decoding the specified array of bytes using the platform's default charset.

    public String(byte bytes[])

    默认字符集合

    System.out.println(Charset.defaultCharset());

    使用指定的字符集合

    public byte[] getBytes(String charsetName)

    Constructs a new String by decoding the specified array of bytes using the specified charset.

    public String(byte bytes[], String charsetName)

    字符集合不相同时会导致看到的字符串不一致,请确保字符集合相同。

    小样:

    byte[] bytes = "字符串".getBytes("utf-8");
    System.out.println(new String(bytes,"utf-8"));// 字符串 
  • 相关阅读:
    字体图标的制作
    vs code 本地调试配置
    瀑布流
    web组件化开发第一天
    超时调用和间歇调用
    递归 闭包
    继承
    面向对象的程序设计
    function类型
    Date类型
  • 原文地址:https://www.cnblogs.com/zno2/p/4626727.html
Copyright © 2011-2022 走看看