Zip file system provider : DirectoryStream « JDK 7 « Java






Zip file system provider


import java.net.URI;
import java.nio.file.DirectoryStream;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;

public class Test {

  public static void main(String[] args) throws Exception {
    Map<String, String> attributes = new HashMap<>();
    attributes.put("create", "true");
    URI zipFile = URI.create("jar:file:/home.zip");
    try (FileSystem zipFileSys = FileSystems.newFileSystem(zipFile, attributes);) {
      Path path = zipFileSys.getPath("docs");
      Files.createDirectory(path);
      try (DirectoryStream<Path> directoryStream = Files
          .newDirectoryStream(zipFileSys.getPath("/"));) {
        for (Path file : directoryStream) {
          System.out.println(file.getFileName());
        }
      }
    }
  }
}

 








Related examples in the same category

1.Writing your own directory filter
2.Using the DirectoryStream interface to process the contents of a directory
3.Get DirectoryStream from a Path with file name matcher