gpt4 book ai didi

java - 如何使用 Spring ClassPathResource : with classpath: or classpath*: and leading/or not?

转载 作者:IT老高 更新时间:2023-10-28 13:48:53 49 4
gpt4 key购买 nike

我在该位置有文件

--src
--> main
--> config
--> application
--> context
--> reference
--> user
--> user.xml

在哪里

    --src
--> main
--> config

在类路径中。现在我正在尝试使用

访问该文件
Resource resource = new ClassPathResource("classpath**:/application/context/references/user/user.xml");
File file = resource.getFile();

但我得到 FileNotFoundException,我尝试了

Resource resource = new ClassPathResource("classpath:/application/context/references/user/user.xml");
File file = resource.getFile();

也是,但我仍然得到异常。有人可以帮助我了解 ClassPathResource 的工作原理和正确的解决方案吗?

最佳答案

如下使用

Resource resource = new ClassPathResource("/application/context/references/user/user.xml");
File file = resource.getFile();

关于java - 如何使用 Spring ClassPathResource : with classpath: or classpath*: and leading/or not?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36588915/

49 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com