1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| package main
import ( "io" "os" )
func main() {
f, _ := os.OpenFile("test.conf", os.O_RDWR|os.O_APPEND, 0666)
f.Write([]byte("hello world!\r\n")) f.WriteString("hello mebaron!\r\n") io.WriteString(f, "hello io pakage!\r\n") f.Close()
f, _ = os.Open("test.conf") defer f.Close() buf := make([]byte, 1024) for { n, _ := f.Read(buf) if n == 0 { break } os.Stdout.Write(buf[:n]) } }
|