mopamaps.blogg.se

Golang write to file
Golang write to file










golang write to file golang write to file

If we reverse the action, we don't see the Hello string in the file.

golang write to file

In this case, we have called the WriteFile method with string s type cast to slice of bytes at the end of the script so we see the file has contents as Hello instead of someA. The function will return an error if any, or else it simply overwrites the data in the file. We have set it as 0660 indicating read(4) + write(2) to the group and the user and no permission to the other users. The first parameter is a string path of the file we want to write the contents to, the third parameter is the file permission. So, we take that slice of byte and parse it to the second parameter of the WriteFile function. The slice of bytes can be taken as a string like someA as the literal value of the underlying slice of the byte. So, we have used the WriteFile method two times in the script, it first takes in a slice of bytes as it is defined as data which corresponds to 115 -> s, 111 -> o, 65 -> A, ASCII mapped to strings. Enter fullscreen mode Exit fullscreen mode












Golang write to file