Here you can find the source of toByteArray(String str)
static byte[] toByteArray(String str)
//package com.java2s; //License from project: Apache License public class Main { static byte[] toByteArray(String str) { char[] chars = str.toCharArray(); byte[] bytes = new byte[chars.length]; for (int i = 0; i != bytes.length; i++) { bytes[i] = (byte) chars[i]; }// w w w .java 2s . c om return bytes; } }