mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 02:35:53 +08:00
28 lines
598 B
Go
28 lines
598 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"bufio"
|
|
"fmt"
|
|
)
|
|
|
|
func main () {
|
|
// var outputWriter *bufio.Writer
|
|
// var outputFile *os.File
|
|
// var outputError os.Error
|
|
// var outputString string
|
|
outputFile, outputError := os.OpenFile("output.dat", os.O_WRONLY|os.O_CREATE, 0666)
|
|
if outputError != nil {
|
|
fmt.Printf("An error occurred with file opening or creation\n")
|
|
return
|
|
}
|
|
defer outputFile.Close()
|
|
|
|
outputWriter := bufio.NewWriter(outputFile)
|
|
outputString := "hello world!\n"
|
|
|
|
for i:=0; i<10; i++ {
|
|
outputWriter.WriteString(outputString)
|
|
}
|
|
outputWriter.Flush()
|
|
} |