tags:

views:

63

answers:

2

In SBT project folders hierarchy I am to put my Scala sources in src/main/scala and tests in src/tests/scala. What am I meant to put into src/main/resources and src/tests/resources?

+1  A: 

Everything in that directory gets packed into the .jar created when you call package.

This means you can use it for images, sound files, text, anything that's not code but is used by your code.

Dylan Lacey
Thank you, Dylan. Can you link to a Scala (2.8) code example on how do I employ these resources then?
Ivan
A: 

Here's an example of copying a text file stored in resource to a local file system:

  def copyFileFromResource(source: String, dest: File) {
    val in = getClass.getResourceAsStream(source)
    val reader = new java.io.BufferedReader(new java.io.InputStreamReader(in))
    val out = new java.io.PrintWriter(new java.io.FileWriter(dest))
    var line: Option[String] = None
    line = Option[String](reader.readLine)
    while (line != None) {
      line foreach { out.println }
      line = Option[String](reader.readLine)
    }
    in.close
    out.flush
  }
eed3si9n