scala 将Scala中BufferedReader的所有行读入一个字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18923864/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 05:42:42 来源:igfitidea点击:
Read All Lines of BufferedReader in Scala into a String
提问by Kevin Meredith
回答by joescii
This is how I deal with a BufferedReaderin Scala:
这就是我BufferedReader在 Scala 中处理 a的方式:
val br:BufferedReader = ???
val strs = Stream.continually(br.readLine()).takeWhile(_ != null)
You will have a string for each line from the reader. If you want it in one single string:
阅读器的每一行都会有一个字符串。如果你想在一个字符串中使用它:
val str = Stream.continually(br.readLine()).takeWhile(_ != null).mkString("\n")

