开发者

Erlang, Is it necessary to close the file here?

When using file:read_file(x) is it n开发者_开发技巧ecessary to close the returned file?

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


It is not a file, but the contents of the file that is returned. Thus, no file to close. Try changing the variable name to Data or similar as in the code below:

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

Data will then have the contents of the file "maillog.sample". The function file:read_file/1 will open, read and close the file for you, all in one go.


No it is not necessary to close the files for file:read_file, and file:consult.

How would you close it anyway, if you don't even have the file descriptor at hand?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜