Read file into Map

Viewed 4476

I have a file named "mappings.txt" of format :

k->v

To read this file into a Map I use :

val file = Source.fromFile("mappings.txt").getLines.filter(f => !f.trim.isEmpty)
val map = file.map(m2 => (m2.split("->")(0), m2.split("->")(1))).toMap

How to read the file into a Map where the values occur over multiple lines ? But some of mappings values are over multiple lines : such as :

k -> v \n 
       test 
       \n here 
k2 -> v2
2 Answers
Related