afero-demo/main.go

22 lines
314 B
Go
Raw Normal View History

2026-02-21 06:10:22 +00:00
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))
}