如何从 lift webapp 读取文件
我想在我的 lift 应用程序中读取 xml 文件:
val data = XML.load(new java.io.InputStreamReader(new java.io.FileInputStream(文件名), 编码));
但是,我收到了java.io.FileNotFoundException
。我应该将该文件放在哪里,以及我的 scala 代码的正确路径是什么?
顺便说一句 - 我正在使用嵌入式码头进行测试,尽管我需要一个用于开发环境和生产的解决方案。
I want to read xml file in my lift app:
val data = XML.load(new java.io.InputStreamReader(new java.io.FileInputStream(filename), encoding));
However, I am getting java.io.FileNotFoundException
. where should I put the file, and what is the correct path from my scala code?
BTW - I am using embedded jetty for my testing, although I need a solution for dev env and production.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于其他路径可能有更好的解决方案,但有
或
通常指向 src/main/resources/ 中的文件。
还有一种
可能是您正在寻找的方法。
There might be better solution for other paths but there is
or
which usually point to files in
src/main/resources/
.There is also
which may be the method you are looking for.
要在一般情况下解决此问题,请
new File("delme").createNewFile()
并查看其最终结果。To solve this problem in the general case,
new File("delme").createNewFile()
and see where it ends up.