如何在播放框架项目中使用相对路径访问资源文件? [英] How to access a resource file using relative path in play framework project?
问题描述
我的 play 框架项目使用资源文件,如我在资源目录下的 CSV 文件,我直接在 play 项目根目录下创建,因此它与其他目录(如 app、public 等)处于同一级别.从 Java 或 Scala 文件中如何我可以使用相对于项目根目录的路径打开此类文件吗?当我创建战争并部署应用程序时,此路径也应该有效.
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");
这篇关于如何在播放框架项目中使用相对路径访问资源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!