init
This commit is contained in:
commit
ad62d9b3e5
|
|
@ -0,0 +1,3 @@
|
|||
afero-demo
|
||||
*.exe
|
||||
go.sum
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
module myschools.me/xinyu/afero-demo
|
||||
|
||||
go 1.24.2
|
||||
|
||||
require (
|
||||
github.com/spf13/afero v1.15.0 // indirect
|
||||
golang.org/x/text v0.34.0 // indirect
|
||||
)
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
|
||||
func main() {
|
||||
//基于内存的文件读写
|
||||
fs := afero.NewMemMapFs()
|
||||
|
||||
afero.WriteFile(fs, "poem.txt", []byte("月光光,照大床"), 0644)
|
||||
|
||||
data, err := afero.ReadFile(fs, "poem.txt")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(string(data))
|
||||
}
|
||||
Loading…
Reference in New Issue