【问题标题】:Fail to get the file in springboot static contentspringboot静态内容中获取文件失败
【发布时间】:2018-03-15 13:44:06
【问题描述】:

我这样写路径时获取不到spring boot静态文件:

 private static final String FILE_PATH = "/resources/data/user.json";

原来是 FileNotFound。我应该如何写路径?

【问题讨论】:

    标签: spring-boot static filenotfoundexception


    【解决方案1】:

    尝试使用 ClasspathResource

    Resource resource = new ClassPathResource("/static/data/user.json");
    File file = resource.getFile();
    

    【讨论】:

    • 抱歉,请问如何在json文件中写入内容。
    猜你喜欢
    • 2014-12-01
    • 2019-09-19
    • 2020-02-09
    • 1970-01-01
    • 2015-11-08
    • 2011-04-17
    • 2016-05-08
    • 2016-11-28
    • 2021-03-25
    相关资源
    最近更新 更多