ruby 1.9 简单的文件操作
发布日期:2021-09-29 20:09:24 浏览次数:8 分类:技术文章

本文共 568 字,大约阅读时间需要 1 分钟。

#读文件 f = File.open("myfile.txt", "r") f.each_line do|line| puts "I read this line: #{line}" end
File.foreach("myfile.txt") do|line| puts "I read this line: #{line}" end
f = File.open("myfile.txt", "r") line = f.gets puts "The line I read is: #{line}"
#写操作 File.open('filename','w') do |f|   f.puts lines end
#得到当前目录所有文件名     files = Dir.glob('*.rd')
#删除特定目录所有文件名 Dir.glob('*.rd').each{|f| File.delete f}
open('myfile.out', 'a') { |f|   f << "Four score\n"   f << "and seven\n"   f << "years ago\n" }
官网File API介绍
[url]http://www.ruby-doc.org/core-1.9.3/File.html[/url]

转载地址:https://blog.csdn.net/horace_lee/article/details/84086073 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:ruby 1.9 irb rails console不能用readline问题
下一篇:MiniTest::Mock 二,进一步示例分析

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月10日 04时28分19秒