--读取13.txt文本内的内容如:
aa001
aa002
aa003
...........
local filePath = "/var/touchelf/13.txt" --读取13.txt文本内的内容如aa001
function readFile(file)
assert(file,"file open failed")
local fileTab = {}
local line = file:read()
while line do
print("get line",line)
table.insert(fileTab,line)
line = file:read()
end
return fileTab
end
function main()
print("start")
local fileRead = io.open(filePath)
if fileRead then
local tab = readFile(fileRead)
fileRead:close()
table.remove(tab,1)
local fileWrite = io.open(filePath,"w")
if fileWrite then
writeFile(fileWrite,tab)
fileWrite:close()
inputText("?????",line)--这里如何让输出的文本实现每次一行
end
local file = io.open("xx.xxx")
for line in file:lines() do
print(line) -- è¿éå°±æ¯æ¯æ¬¡åä¸è¡
inputText("ï¼ï¼ï¼ï¼ï¼",line)--è¿éé¢åºè¯¥ç¨ä»ä¹æ¥è°ç¨è¯»åºæ¥çå
容ï¼
end
line å°±æ¯è¯»åºæ¥çæ¯ä¸è¡æå ä½ æ³æä¹è°ç¨å°±æä¹è°ç¨
æ¯å¦æç¨çæ¹æ³å°±æ¯æä»printåºæ¥
è¿æææ¯å
¨é¨ä¸æ¬¡è¯»åºï¼æ读书å°ï¼ä½ ä¸è¦éªæãã
local file = io.open("xx.xxx")
for line in file:lines() do
print(line) -- è¿éå°±æ¯æ¯æ¬¡åä¸è¡
inputTextï¼lineï¼--------è¿éæææææ¬éææè¡å
¨è¯»äºããã
end
ä½ ä¹¦ç¡®å®è¯»çå° æ²¡è¯»å°è¿ä¸å¿«
æä»¥ä½ è¿è¡ä¸ä¸å°±ç¥éå°åºæ没æé
luaå®æ¹è¯´æææ¡£:
file:lines ()
Returns an iterator function that, each time it is called, returns a new line
from the file. Therefore, the construction
for line in file:lines() do body end
will iterate over all lines of the file. (Unlike io.lines, this function does not close the
file when the loop ends.)