I created a temporary file and renamed it with following statements:
tmp, err := ioutil.TempFile(".", "tmpInter")
, but the permissions on the file changed, as shown in the figure:
This prevented me from opening the file again.
What’s wrong with my program and how can I get it right?
I’m not sure if this is relevant or not, but you’re renaming the file while it’s still open. That might not be the issue, but I would recommend:
- Close the file returned by ioutil.TempFile before attempting to rename it, or at least close it at some point by calling its Close method.
- Don’t discard errors! Maybe ioutil.TempFile is returning an error; maybe os.Rename is.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.