lua讀寫文件


cpFile.lua

 1 function copyfile(source, destination)
 2 sourcefile = io.open(source,"r")
 3 assert(sourcefile)
 4 destinationfile = io.open(destination,"w")
 5 assert(destinationfile)
 6 for line in sourcefile:lines() do
 7 print(line)
 8 destinationfile:write(line)
 9 destinationfile:write("\n")
10 end
11 sourcefile:close()
12 destinationfile:close()
13 end

test.lua

1 dofile("./cpFile.lua")
2 copyfile("./test.txt", "dest.txt")


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM