Skip to content

Instantly share code, notes, and snippets.

@ma6174
Last active February 19, 2020 07:24
Show Gist options
  • Save ma6174/7820579 to your computer and use it in GitHub Desktop.
Save ma6174/7820579 to your computer and use it in GitHub Desktop.
golang 代码片段
f, err := os.Open("a.txt")
defer f.Close()
if nil == err {
buff := bufio.NewReader(f)
for {
line, err := buff.ReadString('\n')
if err != nil || io.EOF == err{
break
}
fmt.Println(line)
}
}
package main
import (
"fmt"
"os"
"path/filepath"
)
func walk(path string) {
err := filepath.Walk(path, func(path string, f os.FileInfo, err error) error {
if f == nil {
return err
}
if f.IsDir() {
return nil
}
fmt.Println(path)
return nil
})
if err != nil {
fmt.Println(err)
}
}
func main() {
walk("./")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment