6

我有一个 .csv 文件,必须在应用程序启动时读取。

我如何才能将这个文件复制到目标(“运行”或“启动”它)。

我正在尝试使用 访问 Global-class 中的此文件Global.class.getResourceAsStream("/file.csv"),但结果始终为空。


好,谢谢。我已经使用 conf/ressources 文件夹中的文件管理它,并使用 /ressources/file.csv 路径加载它

4

3 回答 3

3

你可以把它放在几个地方:

  • 要么在app文件夹中
  • 要么在conf文件夹中:我会去这个,通过创建一个conf/ressources文件夹
于 2012-07-06T08:27:16.103 回答
3

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.

于 2013-08-03T14:23:36.937 回答
0

您可以将它放在test/resources/file.csv播放项目的测试文件夹中的文件夹中。然后你可以在scala中访问它

getClass.getResourceAsStream("/file.csv")

看看这篇博文

于 2014-02-07T12:41:43.980 回答