String.getBytes
Class Overview | Class Members | This Package | All Packages
Syntax 1
public void getBytes( int srcBegin**, int** srcEnd**, byte** dst[], int dstBegin )
Parameters
- srcBegin
index of the first character in the string to copy. - srcEnd
index after the last character in the string to copy. - dst
the destination array. - dstBegin
the start offset in the destination array.
Description
**Note: getBytes() is deprecated.**This method does not properly convert characters into bytes. As of JDK 1.1, the preferred way to do this is via the getBytes(String enc) method, which takes a character-encoding name, or the getBytes() method, which uses the platform's default encoding.
Copies characters from this string into the destination byte array. Each byte receives the 8 low-order bits of the corresponding character.
The first character to be copied is at index srcBegin; the last character to be copied is at index srcEnd-1. The total number of characters to be copied is srcEnd-srcBegin. The characters, converted to bytes, are copied into the subarray of dst starting at index dstBegin and ending at index:
dstbegin + (srcEnd-srcBegin) - 1
Exceptions
StringIndexOutOfBoundsException if srcBegin or srcEnd is out of range, or if srcBegin is greater than srcEnd.
Syntax 2
public byte[] getBytes( String enc ) throws UnsupportedEncodingException
Parameters
- enc
A character-encoding name
Returns
The resultant byte array
Description
Convert this String into bytes according to the specified character encoding, storing the result into a new byte array.
Exceptions
UnsupportedEncodingException If the named encoding is not supported
Syntax 3
public byte[] getBytes()
Returns
the resultant byte array.
Description
Convert this String into bytes according to the platform's default character encoding, storing the result into a new byte array.