Here you can find the source of toByteArray(String string)
Parameter | Description |
---|---|
string | the string to be converted |
public static byte[] toByteArray(String string)
//package com.java2s; //License from project: Apache License public class Main { /**//from w w w . java 2 s . com * Convert the passed in String to a byte array by taking the bottom 8 bits * of each character it contains. * * @param string * the string to be converted * @return a byte array representation */ public static byte[] toByteArray(String string) { byte[] bytes = new byte[string.length()]; char[] chars = string.toCharArray(); for (int i = 0; i != chars.length; i++) { bytes[i] = (byte) chars[i]; } return bytes; } }