public class Solution {
public static void main(String[] args) throws IOException {
Map<String, ByteArrayOutputStream> map = new HashMap<>();
try (ZipInputStream zip = new ZipInputStream(new FileInputStream(args[0]))) {
ZipEntry zipEntry;
while ((zipEntry = zip.getNextEntry()) != null) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] b = new byte[1024];
int count = 0;
while ((count = zip.read(b)) != -1) {
output.write(b, 0, count);
}
map.put(zipEntry.toString(), output);
zip.closeEntry();
}
}
//
//
//
try (ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(args[1]))) {
String fileName = args[0].substring(args[0].lastIndexOf(File.separator) + 1);
ZipEntry zipka = new ZipEntry("new/" + fileName);
zipOutputStream.putNextEntry(zipka);
Files.copy(Paths.get(args[0]), zipOutputStream);
zipOutputStream.closeEntry();
//
//
//
for (Map.Entry<String, ByteArrayOutputStream> pair : map.entrySet()) {
ZipEntry zip9275 = new ZipEntry(pair.getKey());
if (!zip9275.toString().endsWith(fileName)) {
zipOutputStream.putNextEntry(zip9275);
zipOutputStream.write(pair.getValue().toByteArray());
zipOutputStream.closeEntry();
}
}
}
}
}
Константин
1 уровень
Почему не проходит ни один пункт валидатора?
Решен
Комментарии (1)
- популярные
- новые
- старые
Для того, чтобы оставить комментарий Вы должны авторизоваться
--------Master
18 августа 2018, 15:10решение
1. В методе main создай ZipInputStream для архивного файла (второй аргумент main). Нужно вычитать из него все содержимое.
+4