Saturday, March 17, 2012

Go : read and write in a file


To read or write in a file, you can use the package io/ioutil which contains méthods like ReadFile orWriteFile

Example :

package main
import ("fmt";"io/ioutil")
func main() {
fmt.Print("Lecture \n");
contents,_ := ioutil.ReadFile("/home/damikde/tmp/server.log")
   println(string(contents))
        fmt.Print("Ecriture \n");
   ioutil.WriteFile("/home/damikde/tmp/toto", contents, 0x777)
}

No comments:

Post a Comment