Skip to content

Instantly share code, notes, and snippets.

@alonsoir
Forked from ninthdrug/parse_properties.scala
Created May 27, 2017 20:33
Show Gist options
  • Save alonsoir/353cc406b6480256ef6f90c081c9e546 to your computer and use it in GitHub Desktop.
Save alonsoir/353cc406b6480256ef6f90c081c9e546 to your computer and use it in GitHub Desktop.
Parsing java properties files with Scala
import scala.io.Source.fromFile
def parseProperties(filename: String): Map[String,String] = {
val lines = fromFile(filename).getLines.toSeq
val cleanLines = lines.map(_.trim).filter(!_.startsWith("#")).filter(_.contains("="))
cleanLines.map(line => { val Array(a,b) = line.split("=",2); (a.trim, b.trim)}).toMap
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment