Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to read a file from a lift webapp

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.

like image 454
oshai Avatar asked Sep 25 '11 16:09

oshai


2 Answers

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.

like image 131
Debilski Avatar answered Oct 16 '22 11:10

Debilski


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

like image 2
Duncan McGregor Avatar answered Oct 16 '22 10:10

Duncan McGregor