How can you set file permissions when creating a new file in Go?
- Using the os.Create function with the os.FileMode argument.
- Using the os.NewFile function with the os.FileMode argument.
- Using the os.OpenFile function with the os.FileMode argument.
- Using the os.Open function with the os.FileMode argument.
You can set file permissions when creating a new file in Go by using the os.Create function and providing the desired permissions as an argument using the os.FileMode type. For example, os.Create("myfile.txt") can be used to create a new file with default permissions, while os.Create("securefile.txt", 0644) can be used to create a new file with specific permissions (0644 in this case). The os.FileMode type allows you to specify both the file's permission bits and its mode.
Loading...
Related Quiz
- How does Go handle method resolution when multiple embedded interfaces have methods with the same name?
- In Go, a benchmark function's name must start with ______.
- You have obtained benchmark results for your Go program and identified a function with high memory allocations. How would you proceed to optimize this?
- Creating custom error types allows for _____, facilitating better error handling and analysis.
- What is the usual way to handle an error returned by a function in Go?