The missing line!

Report a typo

Below you can see a snippet of code that uses os.OpenFile() to create a file — new_file.txt and afterward open it in the write-only mode. However, there is a very important line of code missing that we need to add just before the program ends:

package main

import (
    "log"
    "os"
)

func main() {
    // Create and Open "new_file.txt" in the write-only mode
    file, err := os.OpenFile("hello.txt", os.O_CREATE|os.O_WRONLY, 0644)
    if err != nil {
        log.Fatal(err)
    }

    // What should we do with the file before the program ends?
    ? // the missing line goes here!
}

Enter below a short text with the missing line:

Enter a short text
___

Create a free account to access the full topic