// - - - - - 构造器的重载 - - - - -/** * Constructs a new String by decoding the specified array of bytes using the platform's default charset. The length of the new {@code String} is a function of the charset, and hence may not be equal to the length of the byte array. * * @since JDK1.1 */public String(byte bytes[]) { this(bytes, 0, bytes.length);} /** * Constructs a new {@code String} by decoding the specified array of bytes using the specified charset. The length of the new {@code String} is a function of the charset, and hence may not be equal to the length of the byte array. * * @param bytes - The bytes to be decoded into characters * @param charsetName - The name of a supported {@linkplain java.nio.charset.Charset charset} * @throws UnsupportedEncodingException - If the named charset is not supported * * @since JDK1.1 */public String(byte bytes[], String charsetName) throws UnsupportedEncodingException { this(bytes, 0, bytes.length, charsetName);} // - - - - - getBytes方法的重载 - - - - - /** * Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array. * * @since JDK1.1 */public byte[] getBytes() { return StringCoding.encode(value, 0, value.length);} /** * Encodes this {@code String} into a sequence of bytes using the named charset, storing the result into a new byte array. * (使用指定的字符集将此字符串编码为字节序列,并将结果存储到一个新的字节数组中。) * * @param charsetName - The name of a supported {@linkplain java.nio.charset.Charset charset} * @return The resultant byte array * @throws UnsupportedEncodingException - If the named charset is not supported * * @since JDK1.1 */public byte[] getBytes(String charsetName) throws UnsupportedEncodingException { if (charsetName == null) throw new NullPointerException(); return StringCoding.encode(charsetName, value, 0, value.length);} |