1. 程式人生 > >String類的getBytes()方法

String類的getBytes()方法

String類的getBytes()方法

1.方法簡介

  /**
     * Encodes this {@code String} into a sequence of bytes using the given
     * {@linkplain java.nio.charset.Charset charset}, storing the result into a
     * new byte array.
	   將這個String以給定的charset 編碼成一個位元組序列,並將這個結果儲存到一個新的位元組陣列中
     *
     * <p> This method always replaces malformed-input and unmappable-character
     * sequences with this charset's default replacement byte array.  The
     * {@link java.nio.charset.CharsetEncoder} class should be used when more
     * control over the encoding process is required.
	   
     *
     * @param  charset
     *         The {@linkplain java.nio.charset.Charset} to be used to encode
     *         the {@code String}
     *
     * @return  The resultant byte array 	結果生成的位元組陣列
     
     * @since  1.6
     */
public byte[] getBytes(Charset charset) { if (charset == null) throw new NullPointerException(); return StringCoding.encode(charset, value, 0, value.length); }

2.方法使用