Here you can find the source of toByteArray(String value)
public static byte[] toByteArray(String value)
//package com.java2s; public class Main { public static byte[] toByteArray(String value) { int i, j; int len = value.length(); if (value == null) { return null; } else if (value == "") { return null; } else if ((len % 2) != 0) { return null; }//from www . j a v a 2 s. c o m try { byte[] byteValue = new byte[len / 2]; j = 0; for (i = 0; i < byteValue.length; i++) { byteValue[i] = (byte) Integer.parseInt( value.substring(j, j + 2), 16); j += 2; } return byteValue; } catch (Exception e) { return null; } } }