我有一个 .csv 文件,必须在应用程序启动时读取。
我如何才能将这个文件复制到目标(“运行”或“启动”它)。
我正在尝试使用 访问 Global-class 中的此文件Global.class.getResourceAsStream("/file.csv"),但结果始终为空。
好,谢谢。我已经使用 conf/ressources 文件夹中的文件管理它,并使用 /ressources/file.csv 路径加载它
我有一个 .csv 文件,必须在应用程序启动时读取。
我如何才能将这个文件复制到目标(“运行”或“启动”它)。
我正在尝试使用 访问 Global-class 中的此文件Global.class.getResourceAsStream("/file.csv"),但结果始终为空。
好,谢谢。我已经使用 conf/ressources 文件夹中的文件管理它,并使用 /ressources/file.csv 路径加载它
你可以把它放在几个地方:
app文件夹中conf文件夹中:我会去这个,通过创建一个conf/ressources文件夹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");
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.
您可以将它放在test/resources/file.csv播放项目的测试文件夹中的文件夹中。然后你可以在scala中访问它
getClass.getResourceAsStream("/file.csv")
看看这篇博文。