Figured out how to add file lines to array
This commit is contained in:
parent
93bd23b848
commit
1bf9e3e27c
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
@ -16,18 +17,17 @@ func main() {
|
|||
|
||||
filePath := os.Args[1]
|
||||
|
||||
names, err := fileReader(filePath)
|
||||
file, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
fmt.Println(names)
|
||||
defer file.Close()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
names = append(names, scanner.Text())
|
||||
}
|
||||
|
||||
func fileReader(path string) (str string, err error) {
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
stre := string(b)
|
||||
return stre, err
|
||||
fmt.Println(names)
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue