go常用代码片段_golang常用代码

//打开文件->逐行读取->根据空格分割打印

package main

import (
"bufio" //缓存io
"fmt"
"io" //基础io ioutil工具包
"os"
"strings"
)

func main() {

f, err := os.Open("D:\\go\\src\\W3SVC10024\\ex150414.log")
defer f.Close()
if err == nil {
r := bufio.NewReader(f)
for {

con, err := r.ReadString('\n')
if err != nil || io.EOF == err {
break
}
s := strings.Split(con, " ")
fmt.Println(s[3])

}
}
}

你可能感兴趣的:(golang)