--拷贝文件的第一中方法,不会用
function Enemy:filecopy(src,dest)
if src==nil or dest==nil or src=='' or dest=='' then
return false
end
local src_fs=io.open(src,'rb')
if src_fs~=nil then
--os.execute('cmd /c copy /y '..src..' '..dest)
os.execute('cp -b'..src..' '..dest)
local dest_fs=io.open(dest,'rb')
if dest_fs==nil then
return false
else
return true
end
end
end
--拷贝文件的第二种方法,不会乱行
function Enemy:getFile(file_name)
local f = assert(io.open(file_name, 'r'))
local string = f:read("*all")
f:close()
return string
end
function Enemy:write_content( fileName,content )
local f = assert(io.open(fileName, 'w'))
f:write(content)
f:close()
end
function Enemy:filecopy1(source,destination)
local stt=self:getFile(source)
self:write_content( destination,stt)
--拷贝文件的第三种方法 会乱行
--[[sourcefile = io.open(source,'rb')
destinationfile = io.open(destination,'wb')
for line in sourcefile:lines() do
destinationfile:write(line)
end
sourcefile:close()
destinationfile:close()]]
function Enemy:filecopy(src,dest)
if src==nil or dest==nil or src=='' or dest=='' then
return false
end
local src_fs=io.open(src,'rb')
if src_fs~=nil then
--os.execute('cmd /c copy /y '..src..' '..dest)
os.execute('cp -b'..src..' '..dest)
local dest_fs=io.open(dest,'rb')
if dest_fs==nil then
return false
else
return true
end
end
end
--拷贝文件的第二种方法,不会乱行
function Enemy:getFile(file_name)
local f = assert(io.open(file_name, 'r'))
local string = f:read("*all")
f:close()
return string
end
function Enemy:write_content( fileName,content )
local f = assert(io.open(fileName, 'w'))
f:write(content)
f:close()
end
function Enemy:filecopy1(source,destination)
local stt=self:getFile(source)
self:write_content( destination,stt)
--拷贝文件的第三种方法 会乱行
--[[sourcefile = io.open(source,'rb')
destinationfile = io.open(destination,'wb')
for line in sourcefile:lines() do
destinationfile:write(line)
end
sourcefile:close()
destinationfile:close()]]
end
function Enemy:ctor()
local path = CCFileUtils:sharedFileUtils():fullPathForFilename("Chapter1.xml")
local nowpath=CCFileUtils:sharedFileUtils():getWritablePath()
local destination=nowpath .."Chapter1.xml"
if io.exists(destination) then
print("这个文件是存在的")
else
print("这个文件是不存在的,快快执行拷贝吧")
print(path)
print("上面是当前地址")
print(destination)
print("上面是目的地址")
self:filecopy1(path,destination)
print("拷贝完成,快去看看吧")
end
end