Skip to content

Instantly share code, notes, and snippets.

View SkyrocketStan's full-sized avatar

Stanislav Rakitov SkyrocketStan

View GitHub Profile
@SkyrocketStan
SkyrocketStan / getAllFilenamesAndDirectoriesSorted
Last active July 9, 2021 09:43
Get a List of all files and subfolders from a directory with Java
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;
}