Cookies management by TermsFeed Cookie Consent
Russia has invaded Ukraine and already killed tens of thousands of civilians, with many more raped or tortured. It's a genocide. We need your help. Let's fight back against the Russian regime.
Help Ukraine! Fight the Russian regime!

๐Ÿค Create a new file in Go

shorts introduction file

Please consider supporting us by disabling your ad blocker

To create a new empty file in Go, use the os.Create() function.

package main

import (

func main() {
    f, err := os.Create("testFile.txt")
    if err != nil {
    defer f.Close()

Always remember to close the open file descriptor when you finish working with the file so that the system can reuse it:

defer f.Close()

You can then write data to this file. See how to do this in one of our previous tutorials here.

๐Ÿงน Delete or remove a file in Go

shorts introduction file

๐Ÿ“ Create a directory in Go

Learn how to create a single or a hierarchy of directories
introduction file

๐Ÿ“Ž Convert JSON to CSV in Go

Learn how to transform JSON file to CSV
introduction file json csv