Hi everyBody, the program fails to pass testing, I already did a test on my machine and the program responds to the requirements. Can you please help me ? thanks a lot.
package com.codegym.task.task31.task3106;
/*
Unzipping a file
*/
import java.io.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class Solution {
public static void main(String[] args) throws IOException {
// Create a file if it's not already done
File fileResult = new File(args[0]);
if (!fileResult.exists()) {
fileResult.createNewFile();
}
// This ArrayList will contain All the FileInputStream Parts
ArrayList<FileInputStream> fileInputStreamList = new ArrayList<FileInputStream>();
// This ArrayList will contain All the names of the file Parts
ArrayList<String> fileListPath = new ArrayList<>();
// Add the names of the file Parts to the Arraylist
for (String arg : args)
{
fileListPath.add((arg));
}
// Sort the names of the file parts alphabetically
Collections.sort(fileListPath);
// Create a FileInputStream for every file and add it to the ArrayList of the streams
for (String filePath : fileListPath)
{
fileInputStreamList.add(new FileInputStream(new File(filePath)));
}
// Create a sequence of InputStream from the list of The FileInputStream above
SequenceInputStream sequenceInputStream = new SequenceInputStream(Collections.enumeration(fileInputStreamList));
// Create a ZipInputStream for the archive assembled from the file parts
ZipInputStream fileInputStream = new ZipInputStream(sequenceInputStream);
// Create an output stream to the file passed as main's first argument
OutputStream fileOutputStream = new BufferedOutputStream(new FileOutputStream(fileResult));
ZipEntry zipEntry = null;
byte[] buffer = new byte[1024];
int len;
while (((zipEntry = fileInputStream.getNextEntry()) != null))
{
while ((len = fileInputStream.read(buffer, 0, 1024)) > 0)
{
fileOutputStream.write(buffer, 0, len);
}
fileOutputStream.flush();
}
// The stream used to read from the archive
fileInputStream.close();
// The stream used to write to the file
fileOutputStream.close();
sequenceInputStream.close();
}
}