Decode a String into a byte array - Android java.lang

Android examples for java.lang:Byte Array

Description

Decode a String into a byte array

Demo Code

import android.util.Log;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;

public class Main{
    public static final String ENCODER = "ISO-8859-1";
    /**// w ww  . j  a v a  2s . com
     * Decode a String into a byte array
     * @param s     String to decode
     * @return      Decoded byte array
     */
    public static byte[] string2Bin(String s) {
        byte[] encoded_data = null;

        try {
            encoded_data = s.getBytes(ENCODER);
        } catch (UnsupportedEncodingException e) {
            Log.d("debug", e.toString());
        }

        return encoded_data;
    }

}

Related Tutorials