package main import ( "fmt" "github.com/spf13/afero" ) func main() { fs := afero.NewOsFs() file, _ := fs.Create("example.txt") fmt.Fprintln(file, "Hello, world!") file.Close() }
package main import ( "fmt" "github.com/spf13/afero" ) func main() { fs := afero.NewOsFs() content, _ := afero.ReadFile(fs, "example.txt") fmt.Println(string(content)) }In this example, we create a new file system object using `NewOsFs`, and then use `afero.ReadFile` to read the contents of the "example.txt" file. The `ReadFile` function returns the content of the file as a byte slice, which we convert to a string using the `string` function and print to the console using `fmt.Println`. Overall, the github.com/spf13/afero package is a useful library for working with files and directories in a file system-agnostic way. The library provides a consistent interface that works across different file systems, which makes it easy to write cross-platform and cross-environment code that interacts with files and directories.