This commit is contained in:
parent
ad62d9b3e5
commit
117c2be9de
|
|
@ -1,3 +1,4 @@
|
||||||
afero-demo
|
afero-demo
|
||||||
*.exe
|
*.exe
|
||||||
go.sum
|
go.sum
|
||||||
|
*.txt
|
||||||
24
main.go
24
main.go
|
|
@ -18,4 +18,28 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(string(data))
|
fmt.Println(string(data))
|
||||||
|
|
||||||
|
//真实文件系统
|
||||||
|
fs = afero.NewOsFs()
|
||||||
|
|
||||||
|
afero.WriteFile(fs, "poem.txt", []byte("月光光,照大床(文件系统)"), 0644)
|
||||||
|
|
||||||
|
data, err = afero.ReadFile(fs, "poem.txt")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(string(data))
|
||||||
|
|
||||||
|
//拷贝文件
|
||||||
|
err = afero.WriteFile(fs, "poem_copy.txt", data, 0644)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
//限定根目录
|
||||||
|
bfs := afero.NewBasePathFs(afero.NewOsFs(), "/home/yy/project")
|
||||||
|
if _, err := bfs.Open("/etc/passwd"); err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue