quick-cocos2d-x(lua) 文件拷贝操作

--拷贝文件的第一中方法,不会用
 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值