Created
August 4, 2022 22:02
-
-
Save joakime/038984edd4fc88f2de74c06454e3e46c to your computer and use it in GitHub Desktop.
Walk all of JRT with Java NIO FileSystem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fs; | |
import java.io.IOException; | |
import java.net.URI; | |
import java.nio.file.FileSystem; | |
import java.nio.file.FileSystems; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.util.Map; | |
import java.util.concurrent.atomic.AtomicInteger; | |
import java.util.stream.Stream; | |
public class JrtDemo | |
{ | |
public static void main(String[] args) throws IOException | |
{ | |
URI jrtRoot = URI.create("jrt:/"); | |
Map<String,?> env = Map.of(); | |
try (FileSystem fs = FileSystems.newFileSystem(jrtRoot, env)) | |
{ | |
Path root = fs.getPath("/"); | |
try (Stream<Path> walkStream = Files.walk(root)) | |
{ | |
final AtomicInteger i = new AtomicInteger(0); | |
walkStream.forEach((path) -> | |
{ | |
String type = ""; | |
if (Files.isDirectory(path)) | |
type = "[dir]"; | |
System.out.printf("[%d] %s %s%n", i.incrementAndGet(), path.toUri(), type); | |
}); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment