BAEL-5033 create file if it doesn't exist

This commit is contained in:
Loredana Crusoveanu 2021-09-16 15:50:41 +03:00
parent 8c7827bebd
commit 656c697f4c
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();
}
}