I have a encoded base64 string from a zip file. I try to decode the string and convert to a zip file. I have this code:
Path rootDirectory = FileSystems.getDefault().getPath("/home/myName/driversFolder");
Path tempDirectory = Files.createTempDirectory(rootDirectory, "");
String dirPath = tempDirectory.toString();
String zipfile = "rbdkjsd4934234234adadds==" //base64 string test
FileOutputStream fos = new FileOutputStream(dirPath + "/zipf.zip");
fos.write(Base64.getDecoder().decode(tt));
fos.close();
If I go to the folder, I can see a zip file (zipf.zip
) with the original content and apparently it's a zip .. but it's not. I'm using linux and if i try to unzip zipf.zip
in command line i have the error:
End-of-central-directory signature not found. Either this file is not a zipfile, or it constitutes one disk of a multi-part archive. In the latter case the central directory and zipfile comment will be found on the last disk(s) of this archive.
Apparently it is a zip because file has a .zip name, but is not in zip format. So what is the way to solve this?