Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.util.Base64;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Main {
    public static File convertBase64IntoFile(String base64, String path) {
        File dwldsPath = new File(path);
        byte[] pdfAsBytes = convertBase64IntoByte(base64);
        FileOutputStream os;
        try {
            os = new FileOutputStream(dwldsPath, false);
            os.write(pdfAsBytes);
            os.flush();
            os.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return dwldsPath;
    }

    public static byte[] convertBase64IntoByte(String base64) {
        byte[] decodedString = Base64.decode(base64, Base64.DEFAULT);
        return decodedString;
    }
}