I am new to Julia & this may be a really silly question :) I am running a calculation in Julia & want to output the result to a text file. The main program contains a for loop. After each loop, a single line containing the result for that iteration should be added in the output file(append ). Each line contains multiple values & they should be separated by space.
I checked Julia documentation & syntax seemed quite similar to C++. I have tested that with the following code.
using Distributions
f = open("hello.txt","w")
write(f,"Hello again.")
close(f)
numbers=rand(5)
f = open("hello.txt","a")
write(f,numbers)
close(f)
f = open("hello.txt","a")
numbers=rand(5)
print(numbers)
write(f,numbers)
close(f)
Here, I am writing random numbers to a file preceded by a general hello statement. But the output file looks like this though the numbers array contain float numbers (verified in console output).
Hello again.�7D����?L'Uf���?8��f��?���>��?����XX�?�x�m��?Y�]���?�v�S���?x���]�?�zPL�?
Surely, I am doing something silly. This issue is never reported before. I cannot figure out what is wrong here.
And as a good practice, should we need to put close(f)/flush(f) after appending each line(in case of appending data through for loop ) or using close(f) at the end of operation suffice?
Thank you in advance. (Julia 1.6 , Linux 64 bit)