如何在Go中写入文件

I have seen How to read/write from/to file using golang? and http://golang.org/pkg/os/#File.Write but could not get answer.

Is there a way, I can directly write an array of float/int to a file. Or do I have to change it to byte/string to write it. Thanks.

You can use the functions in the encoding/binary package for this purpose.

As far as writing an entire array at once goes, there are no functions for this. You will have to iterate the array and write each element individually. Ideally, you should prefix these elements with a single integer, denoting the length of the array.

If you want a higher level solution, you can try the encoding/gob package:

Package gob manages streams of gobs - binary values exchanged between an Encoder (transmitter) and a Decoder (receiver). A typical use is transporting arguments and results of remote procedure calls (RPCs) such as those provided by package "rpc".