How to solve these coding exercises:


Coding Exercise #1

Create a new file in the current working directory called info.txt and then close the file. If the file cannot be created (no permissions, wrong path etc) then print out the error and stop the program (do error handling).

Are you stuck? Do you want to see the solution for this exercise? Click here.


Coding Exercise #2

Rename the file created at Exercise #1 to data.txt

Check if file exists before renaming it. If it doesn't exist print a message and stop the program.

Are you stuck? Do you want to see the solution for this exercise? Click here.


Coding Exercise #3

Remove the file created at exercise #1. Take care that the file is now called data.txt (it has been renamed at exercise #2).

Perform error handling.

Are you stuck? Do you want to see the solution for this exercise? Click here.


Coding Exercise #4

Create a Go Program that reads the entire contents of a file called info.txt into a string. You can use ioutil.ReadAll() or any other function you want.

The file exists in the current working directory.

Are you stuck? Do you want to see the solution for this exercise? Click here.


Coding Exercise #5

Create a Go Program that reads the entire contents of a file called info.txt  using a scanner (bufio package) line by line.

The file exists in the current working directory.

Are you stuck? Do you want to see the solution for this exercise? Click here.


Coding Exercise #6

Create a Go Program that:

1. Using single function creates a file called info.txt in the current directory. If the file already exists it will truncate it to zero size.

2. Write the string "The Go gopher is an iconic mascot!" to the file.

Are you stuck? Do you want to see the solution for this exercise? Click here.