Java 8 JarFile Stream

By Yashwant Chavan, Views 2289, Last updated on 06-Nov-2016

In this tutorial you will learn about method. It return an ordered Stream over the ZIP file entries. Entries appear in the Stream in the order they appear in the central directory of the ZIP file.

tags java

Refer below steps.

  • Creates a new JarFile instance to read from the specified file name.
  • return an ordered Stream over the ZIP/Jar file entries.
  • Iterate and print each JarEntry details using forEach() loop.
  • In second example perform filter operation on Stream to find particular file name inside jar file.
  • Define Predicate for filter() operation as file -> file.getName().contains("BasicDynaBean.class"), Which will returns a stream consisting of the elements of this stream that match with given predicate condition.
  • Print resultant Optional<JarEntry> details.

Print all files inside jar using JarStream


import java.util.Optional;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

public class Java8JarStream {
    public static void main(String[] args) {
        try {

            System.out.println("Print all files inside Jar");

            JarFile jarFile = new JarFile("C:\\demo\\commons-beanutils-1.8.3.jar");
   -> System.out.println("Files :- " + file));

            Optional <JarEntry> searchResult =
                .filter(file -> file.getName().contains("BasicDynaBean.class")).findFirst();

            System.out.println("\nSearch for perticular file");


        } catch (IOException e) {



Print All Files
Files :- META-INF/
Files :- org/
Files :- org/apache/
Files :- org/apache/commons/
Files :- org/apache/commons/beanutils/
Files :- org/apache/commons/beanutils/converters/
Files :- org/apache/commons/beanutils/expression/
Files :- org/apache/commons/beanutils/locale/
Files :- org/apache/commons/beanutils/locale/converters/
Files :- org/apache/commons/collections/
Files :- META-INF/NOTICE.txt
Files :- org/apache/commons/beanutils/BasicDynaBean.class
Files :- org/apache/commons/beanutils/BasicDynaClass.class
Files :- org/apache/commons/beanutils/BeanAccessLanguageException.class
Files :- org/apache/commons/beanutils/BeanComparator.class
Files :- org/apache/commons/beanutils/BeanMap$1.class
Files :- org/apache/commons/beanutils/BeanMap$10.class
Files :- org/apache/commons/collections/FastHashMap$KeySet.class
Files :- org/apache/commons/collections/FastHashMap$Values.class
Files :- org/apache/commons/collections/FastHashMap.class
Files :- META-INF/maven/
Files :- META-INF/maven/commons-beanutils/
Files :- META-INF/maven/commons-beanutils/commons-beanutils/
Files :- META-INF/maven/commons-beanutils/commons-beanutils/pom.xml
Files :- META-INF/maven/commons-beanutils/commons-beanutils/

Search Perticular File


Hi there! I am founder of and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][]