Java 如何在SpringMVC的资源中编辑文件?

Java 如何在SpringMVC的资源中编辑文件?,java,eclipse,spring,spring-mvc,Java,Eclipse,Spring,Spring Mvc,我有一个关于SpringMVC的项目,这个资源文件夹被添加到Spring的buildpath中 在某些UI操作中,我想从控制器编辑resources/thirdparty/thirdparty.er文件 所以这里有一些代码是经过尝试的 File inputFile = new File("/home/local/<User>/Desktop/workspace/<ProjectName>/WebContent/resources/thirdparty/thirdpart

我有一个关于SpringMVC的项目,这个资源文件夹被添加到Spring的buildpath中

在某些UI操作中,我想从控制器编辑resources/thirdparty/thirdparty.er文件

所以这里有一些代码是经过尝试的

File inputFile = new File("/home/local/<User>/Desktop/workspace/<ProjectName>/WebContent/resources/thirdparty/thirdparty.er");
结果-它不起作用

后来在网上搜索时,我发现

Resource resource = new ClassPathResource("/thirdparty/thirdparty.ER");
File inputFile = resource.getFile();
结果-正在返回

/home/local//Desktop/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/WEB-INF/classes/thirdparty/thirdparty.er

这不是我想要编辑的文件。 请让我知道如何做到这一点。我不想在eclipse、服务器或系统上有任何路径依赖,它应该完全基于project。

也许您所需要的只是

Resource resource = resourceLoader.getResource("classpath:/thirdparty/thirdparty.ER");
只需像这样自动连接资源加载程序:

@Autowired
private ResourceLoader resourceLoader;
Resource resource = resourceLoader.getResource("classpath:/thirdparty/thirdparty.ER");
@Autowired
private ResourceLoader resourceLoader;