![](/img/trans.png)
[英]How to automatically manage a file system directory tree using Java/Spring?
[英]How to return a file directory(source tree) in spring controller
@GetMapping
public ResponseEntity<List<String>> fileTree(@RequestParam String path) {
File file = new File(BASE_PATH + path);
// check if file exists etc
return ResponseEntity.ok(Arrays.stream(file.listFiles())
.map(File::getName)
.collect(Collectors.toList()));
}
类似的东西应该可以工作,基本上你可以使用File#listFiles
listFiles 将文件放在另一个文件中,然后随心所欲地处理它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.