【问题标题】:Creating a temporary file in lua在 lua 中创建一个临时文件
【发布时间】:2014-06-15 02:48:09
【问题描述】:

我查看了 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

【问题讨论】:

    标签: file upload lua filesystems luafilesystem


    【解决方案1】:

    标准Lua有两种解决方案:

    • io.tmpfile,它返回一个临时文件的句柄。此文件以更新模式打开,程序结束时自动删除。

    • os.tmpname,它返回一个带有可用于临时文件的文件名的字符串。该文件必须在使用前显式打开,并在不再需要时显式删除。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-25
      • 1970-01-01
      • 2017-03-06
      • 1970-01-01
      • 1970-01-01
      • 2013-01-16
      • 2012-06-14
      相关资源
      最近更新 更多