加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

在lua中创建一个临时文件

发布时间:2020-12-15 00:26:10 所属栏目:大数据 来源:网络整理
导读:我看过LuaFileSystem文档,并没有真正理解我如何创建一个临时文件并写入其中. 另外,我不确定我在哪里可以找到我创建的临时文件..在/ tmp? 这是我的函数的样子: do function upload_file(web) f = -- creates a temporary file f:write(file.contents) -- wr
我看过LuaFileSystem文档,并没有真正理解我如何创建一个临时文件并写入其中.
另外,我不确定我在哪里可以找到我创建的临时文件..在/ tmp?

这是我的函数的样子:

do
   function upload_file(web)

      f =  -- creates a temporary file
      f:write(file.contents)     -- writes the content of the file uploaded in the temp file
      f:seek("set",0)          -- we go back at the beginning
      s = f:read("*a")          -- read it out
      print (s)                 -- print it out
      f:close()                 -- close it
   end
end

解决方法

标准Lua有两种解决方案:

> io.tmpfile,返回临时文件的句柄.此文件在更新模式下打开,并在程序结束时自动删除.
> os.tmpname,返回带有可用于临时文件的文件名的字符串.该文件必须在使用前显式打开,并在不再需要时显式删除.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读