public static byte[] stringToBytesASCII(String str){
  byte[] b=new byte[str.length()];
  for (int i=0; i < b.length; i++) {
    b[i]=(byte)str.charAt(i);
  }
  return b;
}

public static byte [ ] stringToBytesASCII ( String str ) { byte [ ] b = new byte [ str . length ( ) ] ; for ( int i = 0 ; i < b . length ; i ++ ) { b [ i ] = ( byte ) str . charAt ( i ) ; } return b ; }
convert a string containing only ascii characters to the equivalent byte array .
