使用命令行解析文件目录,使用Lua读取文件

我在尝试使用Lua在命令行中读取.txt文件,我正在使用“Lua For Windows”,但是按照我尝试的方式它无法正常工作,它不会给我任何错误,也不会返回任何东西,甚至不是'nil'。

我尝试了这个:

file = io.open("C:\Users\user\Desktop\a.txt", "r") --(and my user's name)
io.input(file)
print(io.read())
io.close(file)
点赞
用户107090
用户107090

在 Lua 的引号字符串中,反斜杠是转义字符。

尝试使用 "C:\\Users\\user\\Desktop\\a.txt"

或者使用长字符串来避免问题:[[C:\Users\user\Desktop\a.txt]]

2020-04-29 23:09:52