Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. func ScanFile(filePath string) ([]string, error) {
  2. file, err := os.OpenFile(filePath, os.O_RDONLY, 0666)
  3. if err != nil {
  4. return nil, err
  5. }
  6. defer file.Close()
  7. scanner := bufio.NewScanner(file)
  8. res := make([]string, 0)
  9. for scanner.Scan() {
  10. line := scanner.Bytes()
  11. res = append(res, string(line))
  12. }
  13. if err = scanner.Err(); err != nil {
  14. return nil, err
  15. }
  16. return res, nil
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement