Skip to content

Instantly share code, notes, and snippets.

@SGTMcClain
Created June 26, 2017 17:18
Show Gist options
  • Save SGTMcClain/bdf5488f56899ea306e7b588f79c1476 to your computer and use it in GitHub Desktop.
Save SGTMcClain/bdf5488f56899ea306e7b588f79c1476 to your computer and use it in GitHub Desktop.
Taking a folder of base 64 files and converting them back to BLOBs
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.apache.tomcat.util.codec.binary.Base64;
public class Base64FolderToBinary {
public static void main(String[] args) throws IOException {
File folder = new File("./Path_to_folder/");
File[] listOfFiles = folder.listFiles();
for(File b64File : listOfFiles){
Path thePath = Paths.get(folder + "/" + b64File.getName());
byte[] getB64 = Files.readAllBytes(thePath);
byte[] fromBase64 = Base64.decodeBase64(getB64);
Path fileDestination = Paths.get("./OtherResources/b64_As_AgreementID/outputFiles/" + b64File.getName() + ".pdf");
Files.write(fileDestination, fromBase64); //file written from base64!
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment