티스토리 뷰

공부

[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());
}

https://stackoverflow.com/questions/1844688/how-to-read-all-files-in-a-folder-from-java/70650106#70650106

 

How to read all files in a folder from Java?

How to read all the files in a folder through Java?

stackoverflow.com

 

728x90

'공부' 카테고리의 다른 글

[Java] resource  (0) 2022.01.10
[Java] Orc File  (0) 2022.01.10
[Java] files  (0) 2022.01.10
[JUnit] Assert API  (0) 2022.01.10
[Java] type: a.getClass().getName()  (0) 2022.01.10
[MySQL] CREATE USER IF NOT EXISTS 'user'@'localhost' IDENTIFIED BY 'password';  (0) 2022.01.10
댓글
댓글쓰기 폼