Transfer String to byte of specified length in Java []

find a method. The parameter is that String and length,length are to be converted to the length of byte [], and the result bit is returned to this byte []. There is an example of int to byte []. The desired result is to replace int with the input parameter of String. Please help!

example is as follows:
public static byte [] intToBytes (int value, int len) {

    byte[] b = new byte[len];
    for (int i = 0; i < len; iPP) {
        b[i] = (byte) ((value >> 8 * i));
    }
    return b;
}
Jun.29,2021
Menu