天空分享 http://blog.sciencenet.cn/u/runningabc

博文

Lua程序中复制文本文件的代码

已有 7639 次阅读 2013-4-18 21:53 |系统分类:科研笔记| 复制, 文本文件, lua

function copyfile(source,destination)

sourcefile = io.open(source,'r')

destinationfile = io.open(destination,'w')

for line in sourcefile:lines() do

   destinationfile:write(line)

end

sourcefile:close()

destinationfile:close()

end


copyfile('C:/1.txt','C/2.txt')

将C盘下的1.txt文件复制一份到C盘下的2.txt文件中


对于二进制文件没有试过,不知是否把上面的

sourcefile = io.open(source,'r')

destinationfile = io.open(destination,'w')

改为

sourcefile = io.open(source,'rb')

destinationfile = io.open(destination,'wb')

就可以

有兴趣的可以试验一下



https://blog.sciencenet.cn/blog-268489-681601.html

上一篇:OpenGL球体移动动画,基于VC++ MFC,收藏
下一篇:编译错误:warning C4005]ws2def.h(91): warning C4005:...
收藏 IP: 180.99.51.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-7-28 02:32

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部