Last active
July 9, 2021 09:43
-
-
Save SkyrocketStan/7dd475fa96b2b43b8898a062766fecfc to your computer and use it in GitHub Desktop.
Get a List of all files and subfolders from a directory with Java
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
public List<String> getAllFilenamesAndDirectoriesSorted(String pathToDir) { | |
Path start = Paths.get(pathToDir); | |
try (Stream<Path> stream = Files.walk(start, Integer.MAX_VALUE)) { | |
return stream.map(String::valueOf).sorted().collect(Collectors.toList()); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment