title: "A Simple Txt File Processing Tool by Golang"
date: 2021-01-31T10:04:51+08:00
draft: true
tags: ['go']
author: "dadigang"
author_cn: "大地缸"
personal: "http://www.real007.cn"
关于作者
package main
import (
"bufio"
"fmt"
"io"
"os"
"strings"
)
func main() {
fileName := "0"
file, err := os.OpenFile(fileName, os.O_RDWR, 0666)
if err != nil {
fmt.Println("Open file error!", err)
return
}
defer file.Close()
buf := bufio.NewReader(file)
for {
line, err := buf.ReadString('\n')
line = strings.TrimSpace(line)
//fmt.Println(strings.ReplaceAll(line, " ", "-"))
fmt.Printf("[%s](https://github.com/topics/%s)\n\n", line, line)
if err != nil {
if err == io.EOF {
break
} else {
return
}
}
}
}
有疑问加站长微信联系(非本文作者)