package main
import (
"bufio"
"fmt"
"io"
"os"
)
func main() {
openTxt("d:/Desktop/area.txt")
}
func openTxt(txt string) string {
filePath := txt
file, err := os.Open(filePath)
if err != nil {
fmt.Println("檔案打開失敗 = ", err)
return ""
}
defer file.Close() // 關閉文本流
reader := bufio.NewReader(file) // 讀取文本資料
for {
str, err := reader.ReadString('\n')
if err ==io.EOF {
break
}
fmt.Print(str)
}
fmt.Println("檔案讀取結束")
return ""
}