From the course: Learning the Go Standard Library

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Writing files

Writing files - Go Tutorial

From the course: Learning the Go Standard Library

Start my 1-month free trial

Writing files

- [Tutor] All right, continuing with our investigation into files in go, let's take a look at how to write data to a file. So there's a couple of different ways to create files and we're going to start with the easiest way. So here in the start folder in chapter four, let's go to the write folder and open up the write_start. And we're going to start with the easiest way and we're going to use the ioutil package for this, so we'll in comment those. So the ioutil package gives us some high-level functions for creating files. So let's just go ahead and scroll down the code to where we're going to do our first example and you can see we've got some other functions we're going to fill out later. So let's just do a simple example, we'll dump some data to a file, all right? So I'll just create a variable to hold some data and that's going to be a byte array. And then to create the file in one step, all I need to do is call…

Contents