« first day (3 days earlier)    last day (14 days later) » 

7:40 AM
String ExtractTo = "D:/DZipTest/";
File[] zipFiles = new File("E:/EZipTest/").listFiles();
for (int i = 0; i < zipFiles.length; i++) {
unzipFile(ExtractTo, zipFiles[i]); // <-- This will unzip one file only. "zipFiles" are many but using the indexer [i], you pick one of them only
rezip(zipFiles[i], ExtractTo);
// TODO: delete extracted files here
}
 
 
3 hours later…
10:51 AM
Like this ?for (int i = 0; i < zipFiles.length; i++)
{
try {
ZipFile zipFile = new ZipFile(zipFiles[i]);
zipFile.extractAll(ExtractTo);
} catch (ZipException e) {
e.printStackTrace();
}
}
 
11:26 AM
I re-followed the instructions and did it from the beginning. It came up to this:
public class AddFilesWithAESEncryption2 {

public AddFilesWithAESEncryption2() {

try {
//Extract Zip files as folders
try {

String ExtractedDirectories1 = "D:/DZipTest/";
File folder2 = new File(ExtractedDirectories1);
String ZipSourcePath = "E:/EZipTest/";

String ExtractTo = "D:/DZipTest/";
File[] zipFiles = new File("E:/EZipTest/").listFiles();
for (int i = 0; i < zipFiles.length; i++) {
unzipFile(ExtractTo, zipFiles[i]);
}

File[] listOfFiles2 = folder2.listFiles();
for (int i = 0; i < listOfFiles2.length; i++) {
When I run it, I get an exception like this: D:/DZipTest/Samplesample.pdf
net.lingala.zip4j.exception.ZipException: Expected central directory entry not found (#1)
 
11:46 AM
In this loop
for (int i = 0; i < zipFiles.length; i++) {
unzipFile(ExtractTo, zipFiles[i]);
}
you're unzipping all files first, resulting in a mixture of files.
This might be what you want, but I doubt it. As far as I understand you just want to apply a password to all files but leaving the content the same.
 
Yes the content will be same. I just want to apply password to ZIPPED FILES
 
What about this loop:
String ExtractTo = "D:/DZipTest/";
File[] zipFiles = new File("E:/EZipTest/").listFiles();
for (int i = 0; i < zipFiles.length; i++) {
unzipFile(ExtractTo, zipFiles[i]);
rezip(zipFiles[i], ExtractTo);
// TODO: delete extracted files here
}
Doesn't it work?
 
12:35 PM
No actually what happened is I couldn't come to exact same result of yours when I tried refactoring step by step. I don't know why. I tried three times so my code looks different
 
1:29 PM
The last step is not a refactoring. Refactoring (if done right) does not change the behavior, so refactoring will never fix a bug.
But in your code, there is a bug that needs to be fixed. You need to do that manually and replace existing code by something new. That's what I did there
 

« first day (3 days earlier)    last day (14 days later) »