Last active
February 19, 2020 07:24
-
-
Save ma6174/7820579 to your computer and use it in GitHub Desktop.
golang 代码片段
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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