如何使用play框架项目中的相对路径访问资源文件? [英] How to access a resource file using relative path in play framework project?
问题描述
我的播放框架项目使用像我在资源目录下的CSV文件这样的资源文件,我直接在play project root下创建它,因此它与app,public等其他目录处于同一级别。从Java或Scala文件中如何我可以使用相对于项目根目录的路径打开此类文件吗?在创建war并部署应用程序时,此路径也应该有效。
My play framework project uses resource files like CSV files that I have under resources directory which I created under play project root directly so it is at the same level as other directories like app, public etc. From within Java or Scala files how can I open such files using path that is relative to the project root? This path should also work when I create a war and deploy the application.
推荐答案
VirtualFile 类应该做你需要的一切,特别是方法'fromRelativePath()'。
The VirtualFile class should do everything you need, especially the method 'fromRelativePath()'.
VirtualFile vf = VirtualFile.fromRelativePath("filename.csv");
这篇关于如何使用play框架项目中的相对路径访问资源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!