修复歌词原文和译文交错排列时会出现不对应的问题

This commit is contained in:
Hami Lemon 2022-03-05 13:02:32 +08:00
parent 452db2f7d2
commit f92ddb245b
8 changed files with 183 additions and 40 deletions

12
util.go
View file

@ -36,7 +36,9 @@ func ReadFile(name string) string {
fmt.Printf("打开文件失败:%v\n", err)
os.Exit(1)
}
defer file.Close()
defer func(file *os.File) {
_ = file.Close()
}(file)
data, err := io.ReadAll(file)
if err != nil {
fmt.Printf("读取文件失败:%v\n", err)
@ -46,12 +48,14 @@ func ReadFile(name string) string {
}
func WriteFile(name string, data string) {
file, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE, os.ModePerm)
file, err := os.Create(name)
if err != nil {
fmt.Printf("保存文件失败:%v\n", err)
fmt.Printf("创建结果文件失败:%v\n", err)
os.Exit(1)
}
defer file.Close()
defer func(file *os.File) {
_ = file.Close()
}(file)
nw, err := file.WriteString(data)
if err != nil || nw < len(data) {
fmt.Printf("保存文件失败:%v\n", err)