I also tried to do a local test, what I did is :
create a local zip file, for example zip a music.map file to musicmp3.zip.
I then use
zip musicmp3.zip --out splitArchive.zip -s 3m
Then I ll get files like:
splitArchive.z01 // Zip archive
splitArchive.z02 // for some reason mac shows it as ` Document`
splitArchive.z03 // Showed as Document
splitArchive.zip // Zip archive, but the name suffix is not .z04, but a .zip
I use above to do a local test but the output unzipped file resultFileName.mp3 is zero bytes.
I don't know it is because my code is wrong, or because my file type is not properly created.
Can anyone give me some hints? I have stuck in this question for almost a week :( Thanks!!
package com.codegym.task.task31.task3106;
import java.io.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/*
Unzipping a file
*/
public class Solution {
public static void main(String[] args) throws IOException {
String resultFileName = args[0];
List<Path> zipFiles = new ArrayList<>();
for (int i = 1; i < args.length; i++){
zipFiles.add(Paths.get(args[i]));
}
//sort each zip file part
Collections.sort(zipFiles, Comparator.comparing(Path::getFileName));
FileOutputStream fileOutputStream = new FileOutputStream(resultFileName);
//unzip the entril file by assembling it from its parts
for (Path f : zipFiles){
ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(new FileInputStream(f.toFile())));
ZipEntry entry;
byte[] bytes = new byte[1024];
while( (entry = zipInputStream.getNextEntry()) != null){
int len;
while((len = zipInputStream.read(bytes) )> 0){
fileOutputStream.write(bytes, 0, len);
}
}
zipInputStream.close();
}
fileOutputStream.close();
}
}