【问题标题】:How to create a folder inside the resource folder in SpringBoot app?如何在 Spring Boot 应用程序的资源文件夹中创建文件夹?
【发布时间】:2019-02-08 15:35:21
【问题描述】:

我有一个 SpringBoot 应用程序,我在其中读取了应用程序资源文件夹的文件夹。但我想知道是否也可以创建一个文件夹在资源文件夹中

File folderFrom = ResourceUtils.getFile("classpath:icons/svg/white/");

类似

File folderTo = ResourceUtils.createFolder("classpath:icons/svg/black/");

我试图从 Eclipse 中做到这一点:

@SpringBootApplication
public class SvgManagerApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(SvgManagerApplication.class, args);
    }


    @Override
    public void run(String... args) throws Exception {      
      ..
    }
}   

【问题讨论】:

  • 您是否将 Spring Boot 应用程序作为 JAR 运行?
  • 首先,我们需要确保...您的资源文件夹保证是文件系统上的一个目录(相对于来自 jar/war 的内容)?否则,您可能会花费大量时间来构建一些在开发过程中可以工作的东西,但是一旦您将其打包以将其部署到生产环境中就会失败。如果这些文件实际上是您的应用程序将使用的数据,请考虑提出一种将其保存在数据库中的方法,或者让您的平台提供文件系统文件夹路径作为配置数据,然后您就可以使用了。

标签: java spring spring-boot spring-mvc


【解决方案1】:

您可以使用java.utils在资源目录中创建一个文件夹

new File("/path/directory").mkdirs();

“目录”是您要创建的文件夹的名称

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-28
    • 2018-06-24
    • 2017-03-13
    • 2020-10-12
    • 1970-01-01
    • 1970-01-01
    • 2017-11-08
    • 2014-06-04
    相关资源
    最近更新 更多