공부
[Java] files
승가비
2022. 1. 10. 18:20
728x90
public static List<File> files(String dirname) {
if (dirname == null) {
return Collections.emptyList();
}
File dir = new File(dirname);
if (!dir.exists()) {
return Collections.emptyList();
}
if (!dir.isDirectory()) {
return Collections.singletonList(file(dirname));
}
return Arrays.stream(Objects.requireNonNull(dir.listFiles()))
.collect(Collectors.toList());
}
How to read all files in a folder from Java?
How to read all the files in a folder through Java?
stackoverflow.com
728x90