Files
2026-07-15 20:39:23 +01:00

35 lines
525 B
Go

package main
import (
"bufio"
"fmt"
"os"
"path/filepath"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func write(a, b string) {
path := filepath.Join(a, b)
file, err := os.Create(path)
check(err)
file.Sync()
writer := bufio.NewWriter(file)
writer.WriteString("Created a file\nAnd wrote in it!")
writer.Flush()
}
func main() {
fmt.Println("Leanring go.")
fmt.Println("Adding a function to create a file")
write("./", "file.txt")
fmt.Println("File created successfully. with contents inside")
}