如何在Lua中创建临时文件并询问如何处理长尾词?
- 内容介绍
- 文章标签
- 相关推荐
本文共计328个文字,预计阅读时间需要2分钟。
看过LuaFileSystem文档,但没有真正理解如何创建一个临时文件并写入内容。不清楚在何处可以找到我创建的临时文件。在/tmp中吗?以下是函数的示例:
luado function upload_file(web) -- 创建临时文件 local file=io.open(/tmp/mytempfile.txt, w) if not file then error(无法创建临时文件) end
-- 写入内容 file:write(这是写入的内容) file:close()end
另外,我不确定我在哪里可以找到我创建的临时文件..在/ 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,返回带有可用于临时文件的文件名的字符串.该文件必须在使用前显式打开,并在不再需要时显式删除.
本文共计328个文字,预计阅读时间需要2分钟。
看过LuaFileSystem文档,但没有真正理解如何创建一个临时文件并写入内容。不清楚在何处可以找到我创建的临时文件。在/tmp中吗?以下是函数的示例:
luado function upload_file(web) -- 创建临时文件 local file=io.open(/tmp/mytempfile.txt, w) if not file then error(无法创建临时文件) end
-- 写入内容 file:write(这是写入的内容) file:close()end
另外,我不确定我在哪里可以找到我创建的临时文件..在/ 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,返回带有可用于临时文件的文件名的字符串.该文件必须在使用前显式打开,并在不再需要时显式删除.

