Android Base64 File Decode decoderBase64FileWithFileName(String base64Code, String fileName)

Here you can find the source of decoderBase64FileWithFileName(String base64Code, String fileName)

Description

decoder Base File With File Name

Declaration

public static String decoderBase64FileWithFileName(String base64Code,
        String fileName) 

Method Source Code

//package com.java2s;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import android.os.Environment;

import android.util.Base64;
import android.util.Log;

public class Main {

    public static String decoderBase64FileWithFileName(String base64Code,
            String fileName) {//from   w ww . ja va 2s  . co  m
        String sdStatus = Environment.getExternalStorageState();
        if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { // ??sd????????
            Log.i("TestFile",
                    "SD card is not avaiable/writeable right now.");
            return "unavailable";
        }
        File file = new File("/sdcard/myDoc/");
        if (!file.exists()) {
            file.mkdirs();
        }
        String filePath = "/sdcard/myDoc/" + fileName;
        byte[] buffer = Base64.decode(base64Code, Base64.DEFAULT);
        try {
            FileOutputStream out = new FileOutputStream(filePath);
            out.write(buffer);
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return filePath;
    }
}

Related

  1. decodeToFile(String filePath, String base64)
  2. decodeToFile(String filePath, String base64)