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?
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.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With