我有一个文件存储了一些信息,例如
0,0,0.0,0.00266920744152335,0.0,0.0,0.0
1,0.0,0.0,0.9385656429557993,1.0,0.0,0.0,0
1,0.0,0.0,0.9385656429557993,1.0,0.0,0.0,0
1,0.0,0.0,0.9385656429557993,1.0,0.0,0.0,0
0,0,0.0,0.00266920744152335,0.0,0.0,0.0
...
我创建了另外两个文件,我想在其中分割存储在textLines
val textLines = scala.io.Source.fromFile("data/sample/textFile.txt")
val first = new java.io.PrintWriter("data/sample/first.txt")
val second = new java.io.PrintWriter("data/sample/second.txt")
for (line <- textLines.getLines()) {
val row = line.split(",")
if (row(0).equals("0"))
first.println(line)
if (row(0).equals("1"))
second.println(line)
}
first.close()
second.close()
textLines.close()
first
文件写得很好,second
文件仍为空白。
出了什么问题?
答案 0 :(得分:0)
我不知道为什么,但清理项目可以解决这个问题。