Merge pull request #11231 from eugenp/BAEL-5033-v2

BAEL-5033 create file if it doesn't exist
This commit is contained in:
Loredana Crusoveanu 2021-09-16 15:54:59 +03:00 committed by GitHub
commit 8bb4493d55
2 changed files with 12 additions and 4 deletions

View File

@ -18,9 +18,12 @@ public class ZipMultiFile {
File firstFile = new File("aFile.txt");
File secondFile = new File("bFile.txt");
firstFile.createNewFile();
secondFile.createNewFile();
if (!firstFile.exists()) {
firstFile.createNewFile();
}
if (!secondFile.exists()) {
secondFile.createNewFile();
}
List<File> filesToAdd = Arrays.asList(firstFile, secondFile);

View File

@ -16,7 +16,12 @@ public class ZipSingleFile {
zipParameters.setCompressionLevel(CompressionLevel.HIGHER);
zipParameters.setEncryptionMethod(EncryptionMethod.AES);
ZipFile zipFile = new ZipFile("compressed.zip", "password".toCharArray());
zipFile.addFile(new File("aFile.txt"));
File fileToAdd = new File("aFile.txt");
if (!fileToAdd.exists()) {
fileToAdd.createNewFile();
}
zipFile.addFile(fileToAdd);
zipFile.close();
}
}