Erlang, do I need to close the file here?

When using file:read_file(x) it necessary to close the returned file?

 {ok, File} = file:read_file("maillog.sample"), file:close(File), 
+7
erlang
source share
2 answers

This is not a file, but the contents of the returned file. Therefore, the file does not close. Try changing the variable name to Data or similarly as in the code below:

 {ok, Data} = file:read_file("maillog.sample"), 

Then the data will contain the contents of the file "maillog.sample". Function file: read_file / 1 will open, read and close the file for you, all in one go.

+10
source share

There is no need to close files for file:read_file and file:consult .

How would you close it if you don't even have a file descriptor?

+8
source share

All Articles