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")

相关文章:

  • 2021-12-10
  • 2022-12-23
  • 2022-01-29
  • 2021-10-21
  • 2021-05-30
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案