Join David Gassner for an in-depth discussion in this video Writing to a text file, part of Learning Go.
- Now that I've covered…the basic syntax of the Go programming language,…I'll show you how to accomplish some common tasks.…And I'll start with writing a file…to the local file system.…I'm working the file named writeFile.go.…And I've declared a string variable…with a simple string.…I also have an empty function down here…called checkError that receives an error argument.…I'll start by adding some imports up here.…I'll add a package named io.…And another one named os, for operating system.…
Next, in the main function,…I'll declare a reference to a file object.…I'll name it file.…And the method I'm about to call,…is also going to return an error object.…I'll assign those values from os.Create.…And I'll pass in a string of ./fromString.txt.…Now that file doesn't exist yet,…so this is a pointer to a file that I can create.…Now, I have to handle the error,…but I'm going to be calling a couple…of different methods that might generate an error,…so I'm going to consolidate all my error handling code here,…in my function named checkError.…
- Installing Go tools
- Creating and compiling a Go workspace
- Exploring variables, constants, and types
- Storing ordered and unordered values
- Grouping related values in structs
- Programming conditional logic and loops
- Defining and calling functions
- Handling errors
- Working with files
- Creating a simple HTTP server
Skill Level Beginner
1. Getting Started
2. Essential Go Skills
3. Managing Simple Values
4. Managing Complex Types and Collections
5. Managing Program Flow
6. Structuring Go Code
7. Working with Files and the Web
Next steps2m 26s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.