Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a seq in F# into output file

Tags:

f#

I have problems writing an output file in F#. It prints an incomplete data in the output. I am not sure which part of my code is wrong or if there is any better way to do it. Below is a snapshot of the last few lines in the output file.

NKU12,201209121039,8960,8960,8960,8960
NKU12,201209121040,8960,8960,8960,8960
NKU12,201209121041,8960,8960,8960,8960
NKU12,201209121043,8960,8960,8960,8960
NKU12,201209121045,8960,8

Note that in the last line, it is incomplete. Below is my code in F#

let outFile = new StreamWriter("Test.csv")

let dataFrame = lines fileName
                |> Seq.map (fun y -> y.Split([|','|]))
                |> Seq.filter (fun some function) 
                |> Seq.iter (fun y -> outFile.WriteLine(sprintf "%s,%s,%s,%s,%s,%s" y.[0] (y.[1]+y.[2]) y.[3] y.[4] y.[5] y.[6]))

Note that in the last line, it is incomplete. If I use printfn instead of writing to a file, it will display all the information fully on the console.

Thanks Kenneth

like image 798
Kenneth Goh Avatar asked Sep 22 '12 15:09

Kenneth Goh


1 Answers

Try to call outData.Flush or outData.Close and then check content of the file. Some data may still be in buffer.

like image 92
desco Avatar answered Nov 03 '22 01:11

desco