package scripts
import (
"bufio"
"fmt"
"io"
"os"
)
// 按行读取文件内容
func ReadFile(fileName string, contentChan chan string) {
file, err := os.Open(fileName)
if err != nil {
fmt.Println(err)
}
defer file.Close()
reader := bufio.NewReader(file)
for {
str, _, err := reader.ReadLine()
if err == io.EOF {
break
} else if err != nil {
if err != nil {
fmt.Println(err)
}
}
if len(str) != 0 {
contentChan <- string(str)
}
}
close(contentChan)
}
// 写入文件
func WriteFile(fileName, content string) {
file, _ := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
file.Write([]byte(content))
file.Close()
}