(fileName string)
| 25 | } |
| 26 | |
| 27 | func LinesInFile(fileName string) ([]string, error) { |
| 28 | result := []string{} |
| 29 | f, err := os.Open(fileName) |
| 30 | if err != nil { |
| 31 | return result, err |
| 32 | } |
| 33 | defer f.Close() |
| 34 | scanner := bufio.NewScanner(f) |
| 35 | for scanner.Scan() { |
| 36 | line := scanner.Text() |
| 37 | if line != "" { |
| 38 | result = append(result, line) |
| 39 | } |
| 40 | } |
| 41 | return result, nil |
| 42 | } |
| 43 | |
| 44 | func FileExists(path string) bool { |
| 45 | _, err := os.Stat(path) //os.Stat获取文件信息 |