Here you can find the source of stringToBytes(String str)
public static byte[] stringToBytes(String str)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { public static byte[] stringToBytes(String str) { StringBuffer sb = new StringBuffer(str); char c = sb.charAt(0); ByteBuffer buffer = ByteBuffer.allocate(sb.length() * 2); int index = 0; while (index < sb.length()) { buffer.putChar(sb.charAt(index++)); }/* w w w . j av a 2 s . c o m*/ return buffer.array(); } }