可以的,代码实例如下所示:
控制器如下所示:
@PostMapping(value = "/mkdirDirectory") public Object mkdirDirectory(@RequestParam("path") String path) { log.info("本地生成文件夹路径:{}", path); Object ifSuccess = false; try { ifSuccess = FileService.mkdirDirectory(path); }catch(Exception e){ log.error("本地生成文件夹报错", e); } return ifSuccess; }
service层代码如下所示:
/** * 新建目录 * @param path */ Object mkdirDirectory(String path);
具体service层代码实现类如下所示:
@Override public Object mkdirDirectory(String path) { boolean created = false; File pathFolder = new File(path); if (created=pathFolder.mkdirs()) { log.info("目录创建成功{}", pathFolder.getAbsolutePath()); } else { log.info("目录已存在或创建失败{}", path); } return created; }
测试如下所示: