我正在使用akka-stream来解析文件。在我的文件中,我有标题行在第一位,没有其他地方。如何在我的流中先跳过这个头文件?我不想每次都检查行是否为表头。有没有办法做到这一点?
FileIO.fromPath(path).
via(delimiter(ByteString("\n"), Int.MaxValue)). // split into lines
map(_.decodeString("UTF-8")). // convert ByteStrings to Strings
filter(!_.startsWith("#")). // remove comments
fold(0)((i, _) => i + 1). // count remaining lines
runForeach(println) // run the stream, print result发布于 2019-05-04 02:16:52
如果您正在读取CSV文件,则可以使用Alpakka: Comma-Separated Values - CSV
示例:
Source
.single(ByteString(
"""eins,zwei,drei
|11,12,13
|21,22,23
|""".stripMargin))
.via(CsvParsing.lineScanner())
.via(CsvToMap.toMap())
.fold(0)((i, _) => i + 1)
.runForeach(println)输出:2
https://stackoverflow.com/questions/55970737
复制相似问题