How can I ignore or remove blank lines, when reading from a text file using Scala?
An example is shown below: As you can see, the second line is the extra line.
I. The Period
It was the best of times,
try this.
val file = Source.fromFile(args(0)).getLines().filter(!_.isEmpty()).mkString(" ")
It will remove empty lines from list of lines and then concatenate them into one string with space between lines.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments