Example usage for java.nio.file DirectoryStream forEach

List of usage examples for java.nio.file DirectoryStream forEach

Introduction

In this page you can find the example usage for java.nio.file DirectoryStream forEach.

Prototype

default void forEach(Consumer<? super T> action) 

Source Link

Document

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.

Usage

From source file:org.esa.snap.engine_utilities.util.ZipUtils.java

public static void zipFolder(final Path directory, final File outputZipFile) throws IOException {

    try (ZipOutputStream zipStream = new ZipOutputStream(new FileOutputStream(outputZipFile))) {

        // traverse every file in the selected directory and add them
        // to the zip file by calling addToZipFile(..)
        DirectoryStream<Path> dirStream = Files.newDirectoryStream(directory);
        dirStream.forEach(path -> addToZipFile(path.toFile(), zipStream));
    } catch (IOException e) {
        throw e;//from   w ww  .j  a v a2  s .  co  m
    }
}