private void exploreDirectory(ZipOutputStream zipStream, String root, File directory) { if (directory.isHidden()) { return; } foreach (var content in directory.list()) { var file = new File(directory, content); if (file.isDirectory()) { exploreDirectory(zipStream, root + directory.getName() + '/', file); } else { addEntry(zipStream, root + directory.getName() + '/', file); } } }
private void addEntry(ZipOutputStream zipStream, String root, File file) { if (file.isHidden()) { return; } var name = root + file.getName(); var zipEntry = new ZipEntry(name); zipStream.putNextEntry(zipEntry); var buffer = new byte[4096]; var inputStream = new FileInputStream(file); int read; while ((read = inputStream.read(buffer)) != -1) { zipStream.write(buffer, 0, read); } }