文件没有用scala编写

时间:2015-07-10 08:15:38

标签: file scala

我有一个文件存储了一些信息,例如

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文件仍为空白。

出了什么问题?

1 个答案:

答案 0 :(得分:0)

我不知道为什么,但清理项目可以解决这个问题。