lua中没有文件拷贝的函数,但是有简单的文件读写函数。
以二进制方式读取源文件的全部内容,然后再全部写到目标文件中,就完成了文件的拷贝
1.lua
function copyFunc(destFilePath, sourceFilePath)
local sourceFile, errorString = io.open(sourceFilePath, "rb")
assert(sourceFile ~= nil, errorString)
local data = sourceFile:read("a")
sourceFile:close()
local destFile = io.open(destFilePath, "wb")
destFile:write(data)
destFile:close()
end
copyFunc("E:/Lua_project/lua_learn/2.jpg", "E:/Lua_project/lua_learn/1.jpg")
wind