File.open,写入并保存? [英] File.open, write and save?
本文介绍了File.open,写入并保存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
运行该文件时,我试图获取一个.rb文件以在具有指定内容的特定目录中创建另一个.rb文件.我不知道执行此操作的最佳方法是使用Ruby文件还是使用Rake文件.您的输入会很棒.
I am trying to get a .rb file to make another .rb file within a specific directory with specified content, when that file is run. I dont know whether the best way to do this would be with a Ruby file or a Rake file. You input would be great.
推荐答案
事实证明这是最好的解决方案.
This turned out to be the best solution.
File.open("linecount.txt",'w') do |filea|
File.open("testfile.txt",'r') do |fileb|
while line = fileb.gets
filea.puts line.length
end
end
end
这篇关于File.open,写入并保存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文