package main
import (
"bufio"
"fmt"
"io"
"log"
"os"
"strconv"
)
func main() {
r, err := os.Open("file.txt")
if err != nil {
log.Fatal(err)
}
defer r.Close()
s, err := linesToInt(r)
if err != nil {
log.Fatal(err)
}
fmt.Println(s)
}
func linesToInt(r io.Reader) ([]int, error) {
var arr []int
s := bufio.NewScanner(r)
for s.Scan() {
text := s.Text()
i, err := strconv.Atoi(text)
if err != nil {
continue
}
arr = append(arr, i)
}
err := s.Err()
if err != nil {
return nil, err
}
return arr, nil
}