如何从 lift webapp 读取文件

发布于 2024-12-06 12:56:34 字数 307 浏览 6 评论 0原文

我想在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

在梵高的星空下 2024-12-13 12:56:34

对于其他路径可能有更好的解决方案,但有

var LiftRules.getResource : (String) ⇒ Box[URL]

def LiftRules.doWithResource(name: String)(f: (InputStream) ⇒ T): Box[T]

通常指向 src/main/resources/ 中的文件。

还有一种

def LiftRules.loadResourceAsXml(name: String): Box[NodeSeq]

可能是您正在寻找的方法。

There might be better solution for other paths but there is

var LiftRules.getResource : (String) ⇒ Box[URL]

or

def LiftRules.doWithResource(name: String)(f: (InputStream) ⇒ T): Box[T]

which usually point to files in src/main/resources/.

There is also

def LiftRules.loadResourceAsXml(name: String): Box[NodeSeq]

which may be the method you are looking for.

人生戏 2024-12-13 12:56:34

要在一般情况下解决此问题,请 new File("delme").createNewFile() 并查看其最终结果。

To solve this problem in the general case, new File("delme").createNewFile() and see where it ends up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文