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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *