Skip to content

Instantly share code, notes, and snippets.

@ram0973
Created January 31, 2021 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ram0973/691e7c84ba9bef2cb5cc8efd111e1d1f to your computer and use it in GitHub Desktop.
Save ram0973/691e7c84ba9bef2cb5cc8efd111e1d1f to your computer and use it in GitHub Desktop.
Deepest file or directory
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
class Main {
public static void main(String[] args) throws IOException {
Path longestPath = Files.walk(Paths.get("D:\\Downloads\\basedir"))
.max(Comparator.comparingInt(Path::getNameCount)).orElseThrow(NullPointerException::new);
System.out.println(longestPath.getFileName() + " " + longestPath.getNameCount());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment