package org.ntlab.nemophila.utils; import java.io.*; import java.util.Base64; public class Base64Decode { private static void saveAsFile(String path, String enImage) throws IOException{ File file = new File(path); if(enImage == null) { file.delete(); return; } byte[] deData = Base64.getDecoder().decode(enImage); file.getParentFile().mkdir(); file.createNewFile(); FileOutputStream fileOS = new FileOutputStream(file, false); BufferedOutputStream bf = new BufferedOutputStream(fileOS); bf.write(deData, 0, deData.length); bf.close(); } public static void saveIcon(String id, String path1, String enImage) throws IOException { String fileName = "icon" + id + ".jpg"; String path = path1 + "/" + fileName; saveAsFile(path, enImage); } public static void savePostImage(String id, String pid, String path1, String[] enImage) throws IOException { for(int i = 0; i < enImage.length; i++) { String fileName = "post_image" + id + "-" + pid + "-" + (i+1) + ".jpg"; String path = path1 + "/" + fileName; saveAsFile(path, enImage[i]); } } }