mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-11 19:22:37 +08:00
35 lines
686 B
Go
35 lines
686 B
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
// var inputFile *os.File
|
|
// var inputError, readerError os.Error
|
|
// var inputReader *bufio.Reader
|
|
// var inputString string
|
|
|
|
inputFile, inputError := os.Open("input.dat")
|
|
if inputError != nil {
|
|
fmt.Printf("An error occurred on opening the inputfile\n" +
|
|
"Does the file exist?\n" +
|
|
"Have you got access to it?\n")
|
|
return // exit the function on error
|
|
}
|
|
defer inputFile.Close()
|
|
|
|
inputReader := bufio.NewReader(inputFile)
|
|
|
|
for {
|
|
inputString, readerError := inputReader.ReadString('\n')
|
|
fmt.Printf("The input was: %s", inputString)
|
|
if readerError == io.EOF {
|
|
return // error or EOF
|
|
}
|
|
}
|
|
}
|