Gofileiod Official

_, err = io.Copy(destination, source) return err

defer destination.Close()

defer file.Close() // Full read into []byte data, err := os.ReadFile("data.txt") 3. Writing to a file data := []byte("Hello, Go File I/O") err := os.WriteFile("output.txt", data, 0644) 4. Buffered reading (line by line) scanner := bufio.NewScanner(file) for scanner.Scan() fmt.Println(scanner.Text()) gofileiod