mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 03:06:41 +08:00
* Update 06.4.md 标点符号错误 * Update 06.5.md * Update 06.6.md * Update 06.8.md 修正上一节目录索引错误 * Update 06.8.md * Update 07.0.md * Update 07.1.md * Update 07.6.md 用词不统一 * Update 08.0.md * Update 08.6.md 用词不统一 * Update 09.0.md * Update 09.5.md 修改不通顺 * 拼写错误 [建议加上`git remote -v`](https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/) * Update 10.0.md * 统一风格 * 调整位置,保证最后一行可以输出 * 保证最后一行可以输出 * 格式 * markdown 修改
35 lines
685 B
Go
35 lines
685 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 acces 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
|
|
}
|
|
}
|
|
}
|