作为来自http://ruby.bastardsbook.com/chapters/io/的教程
file = File.open("sample.txt", 'r')
while !file.eof?
line = file.readline
puts line
end
Run Code Online (Sandbox Code Playgroud)
这种方法把每一行,但是当我更换
while !file.eof?
Run Code Online (Sandbox Code Playgroud)
和
unless file.eof?
Run Code Online (Sandbox Code Playgroud)
循环只运行一次,为什么?
| 归档时间: |
|
| 查看次数: |
54 次 |
| 最近记录: |