Created
July 11, 2018 08:53
-
-
Save LaughingVzr/12e48af8fa11672094a2bd08986e104d to your computer and use it in GitHub Desktop.
[Golang 按行读取配置文件] #golang #file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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