如何使用类路径指定Spring项目中文件的位置?
这就是我目前所拥有的:
FileReader fr = new FileReader("C:\\Users\\Corey\\Desktop\\storedProcedures.sql");
Run Code Online (Sandbox Code Playgroud)
这是我的桌面硬编码.我想要的是能够使用我的项目中的文件的路径.
FileReader fr = new FileReader("/src/main/resources/storedProcedures.sql");
Run Code Online (Sandbox Code Playgroud)
有什么建议?
关于classpath:春季期权,我有两个问题: -
1)是否classpath:搜索相对于指定文档的资源(如果是Web应用程序)?
假设我使用以下内容:
<bean class="mybean">
<property name="myresource" value="classpath:myfile.txt"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
在/WEB-INF/classes/config/myconfig.xml下的myconfig.xml中.然后从哪里开始搜索?
2)如果直接定位资源而不是给出classpath:ie ,搜索会更快吗?
<bean class="mybean">
<property name="myresource" value="classpath:/WEB-INF/classes/myfolder/myfile.txt"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
代替
<bean class="mybean">
<property name="myresource" value="classpath:myfile.txt"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
谢谢...