Hi Everyone,
I am just trying something really simple here: write something into a
file. It worked this morning on a windows machine using the windows
port of go. Now I am home and trying it on my Ubuntu 10.04. I am
getting a Bad File Descriptor err. Tried many things and nothing
worked... Here is the code, plz anyone have a look...
Thank you so very much~
// It failed on the Only Write call in the code. The folder exists.
Permission of the folder is: drwxr-xr-x
package main
import (
"strings"
"os"
)
func main() {
file, err := os.Open("
golang.org/golang.org_start_page.html",
os.O_CREATE, 0644)
if err != nil {
panic(err)
}
const NBUF = 512
var buf [NBUF]byte
reader := strings.NewReader("abcdefghijklmnopqrstuvwxyz")
nr, er := reader.Read(&buf)
if er == nil {
if nw, ew := file.Write(buf[0:nr]); nw != nr {
panic(ew)
}
} else {
panic(er)
}
}