mirror of
https://github.com/mudabbir-ahmad/LearningGo.git
synced 2026-10-07 17:50:20 +00:00
35 lines
525 B
Go
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")
|
|
}
|