Is necessary to close a file when you only want create it? I’m supposed that it’s only necessary in case of reading or writing.
_, err := os.OpenFile(name, os.O_CREATE, 0640)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Will it work? Yes. The file will be created.
Should you do it? No. It is a bad idea in general even though you can get away with it sometimes.
Opening a file allocates resources like a file handle to your process. You should close it to free those resources. Otherwise they will be unavailable until the process dies.