简体   繁体   中英

How to return a file directory(source tree) in spring controller

I need to get the file directory from controller. when i do visit to one url I want to get like this. is there any way to create with spring controller by doing a get request without FTP server.

在此处输入图像描述

can someone pleases give me some idea.

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

Something like that should work, basically you can get the files inside another file with File#listFiles and then do with them wathever you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM