Skip to content

Instantly share code, notes, and snippets.

@LaughingVzr
Created July 11, 2018 08:53
Show Gist options
  • Save LaughingVzr/12e48af8fa11672094a2bd08986e104d to your computer and use it in GitHub Desktop.
Save LaughingVzr/12e48af8fa11672094a2bd08986e104d to your computer and use it in GitHub Desktop.
[Golang 按行读取配置文件] #golang #file
// readTestFile 按行读取配置文件
func readTestFile(path string) []string {
var arr []string
file, err := os.Open(path)
if err != nil {
fmt.Println(err)
return arr
}
defer file.Close()
br := bufio.NewReader(file)
for {
a, _, c := br.ReadLine()
if c == io.EOF {
break
}
arr = append(arr, string(a))
}
//fmt.Println(arr)
return arr
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment