使用Lua I / O函数创建新文件 [英] Creating new files with Lua I/O functions

查看:181
本文介绍了使用Lua I / O函数创建新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始了解io。函数,我试图在我的代码中实现它们。我已经搜索过这个问题的答案,似乎没有什么可以明确表示是或否,或者至少我没有看到一个。我希望有人能够知道答案,并能够帮助解决这个问题。

I'm starting to learn about the io. functions, and am trying to implement them in my code. I've searched for the answer to this and nothing seems to give a clear cut yes or no, or at least I don't see one. I'm hoping someone here will know the answer and be able to help with this.

我想创建一个文本文件,随着时间的推移我可以写入。它基本上是一个日志,我将附加输出行。显然io.open(textfile.txt)不会创建文件,或者它出现。

I'm wanting to create a text file that I can write to as time progresses. It'll basically be a log to which I'll be appending lines of output. Apparently io.open("textfile.txt") does not create the file, or so it appears.

有没有办法在Lua中创建一个可以的文本文件以后可以用io.read/write访问?另外,在打开或创建新文本文件之前,是否需要调用io.close()?我感谢任何帮助。谢谢!

Is there a way to create a text file in Lua that can later be accessed with io.read/write? Additionally, do I need to call io.close() before opening or creating a new text file? I appreciate any help given. Thanks!

推荐答案

您需要打开的文件,如下所示: F = io.open( TextFile.txt的, W)。然后使用 f:write()写入内容。完成写作后,请致电 f:close()

You need to open the file for writing as follows: f=io.open("textfile.txt","w"). Then use f:write() to write stuff to it. When finished writing, call f:close().

这篇关于使用Lua I / O函数创建新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆