使用缓冲区读取器读取 scala 中的文件



我在临时目录中有一个输入文件

我必须读取文件并取第二行,然后删除前两个单词并将字符串保存在变量中。我正在尝试使用缓冲阅读器而不是从源读取文件。

该文件是文档.txt如下所示

#doc source topic proportion ...
0 src/main/tempDir/new_corpus/0c3da178-2d99-453d-8d54-0ee4212f1ed8 186 0.005347593582886886 185 0.005347593582886886 184 0.005347593582886886 183 0.005347593582886886 182 0.005347593582886886 181 0.005347593582886886 180 0.005347593582886886 179 0.005347593582886886 178 0.005347593582886886 177 0.005347593582886886 176 0.005347593582886886 175 0.005347593582886886 174 0.005347593582886886 173 0.005347593582886886 172 0.005347593582886886 171 

我必须从"186 0.0053....">

我使用的代码是

val in = new BufferedReader(new FileReader("src/main/tempDir/doc.txt"))
val l: String = in.readLine()

但从这里我无法得到想要的结果,请建议

in.readLine                        //skip 1st line
val l: String = in.readLine()
                  .split("\s+")  //split on whitespace
                  .drop(2)
                  .mkString(" ")  //restore whitespace
//l: String = 186 0.005347593582886886 185 0.00...

最新更新