Play Framework自定义资源:如何复制到目标? [英] Play Framework custom resources: how to copy to target?
问题描述
我有一个.csv文件,必须在应用程序启动时读取.
I have a .csv file, that must be read on application startup.
如何发挥作用将此文件复制到目标(运行"或启动").
How can I make play to copy this file to target (to "run" or "start" it).
我正在尝试使用Global.class.getResourceAsStream("/file.csv")
访问全局类中的该文件,但结果始终为空.
I'm trying to access this file in Global-class with Global.class.getResourceAsStream("/file.csv")
, but the result is always null.
好的-谢谢. 我已经用conf/ressources文件夹中的文件管理了它,并使用/ressources/file.csv路径加载了它
OK - thanks. I have managed it with my file in conf/ressources folder and loading it with /ressources/file.csv path
推荐答案
您可以在conf
文件夹中创建resources
文件夹,将文件放在此处,然后通过调用创建InputStream
You can create a resources
folder in your conf
folder, put your file there, and then create an InputStream
by calling
Play.classloader.getResourceAsStream("resources/file.csv");
请注意,您不应使用/
开头路径,因为这样应用程序将无法解析路径并在启动时抛出java.lang.ExceptionInInitializerError: null
.
Note that you should not start the path with a /
, because then the application will not be able to resolve the path and throw a java.lang.ExceptionInInitializerError: null
on startup.
这篇关于Play Framework自定义资源:如何复制到目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!