I need get all user input in stdin as single string in scala 2.12 (supposed the data would copy-pasted by single action), something like this:
please copy data:
word1
word2
word3
And I need get string with following data:
val str = "word1\nword2\nword3"
my current approach is not working, just hanging forever:
import scala.collection.JavaConverters._
val scanner: Iterator[String] = new Scanner(System.in).asScala
val sb = new StringBuilder
while (scanner.hasNext) {
sb.append(scanner.next())
}
val str = sb.toString()
Although this can print the input:
import scala.collection.JavaConverters._
val scanner: Iterator[String] = new Scanner(System.in).asScala
scanner foreach println
I'm looking for idiomatic way of doing the job