Last active
October 18, 2019 06:35
-
-
Save ninthdrug/4068637 to your computer and use it in GitHub Desktop.
Parsing java properties files with Scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
you gotta close the file to prevent a leak.
can be split like