base64 decode UTF-8 string - Android File Input Output

Android examples for File Input Output:Base64

Description

base64 decode UTF-8 string

Demo Code


//package com.java2s;

import android.util.Base64;

import java.io.UnsupportedEncodingException;

public class Main {
    public static String decode(String s) {
        byte[] data = Base64.decode(s, Base64.DEFAULT);
        String text = "";
        try {/*  ww w .  j  a  v a2 s .c  o m*/
            text = new String(data, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return text;
    }

    public static String decode(byte[] data) {
        String text = "";
        try {
            text = new String(data, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return text;
    }
}

Related Tutorials