问题
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.
回答1:
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.
回答2:
To solve this problem in the general case, new File("delme").createNewFile()
and see where it ends up.
来源:https://stackoverflow.com/questions/7546887/how-to-read-a-file-from-a-lift-webapp