|
|
 |
 |
 |
|
|
| Author Details |
Code Information |
|
|
|
Language
|
Plain Text
|
|
Expires
|
Never
|
|
Length
|
411 Characters (15 Lines)
|
|
Password
|
no password
|
|
|
|
Description
Another Ruby Function
#p027readwrite.rb # Open and read from a text file # Note that since a block is given, file will # automatically be closed when the block terminates File.open('any.rb', 'r') do |f1| while line = f1.gets puts line end end # Create a new file and write to it File.open('test.rb', 'w') do |f2| # use "\n" for two lines of text f2.puts "Created by Damner\nCool!" end |
|
| Please login to post comments. |
|
|
Alternatively:
File.open('[file]', 'r') do |file|
puts file.read
end
|
|
|
I haven't played with file IO, but it looks pretty good.
|
|
|
|
|
| |
 |
 |
| |
::
::
::
::
|
Version 1.44.00
Copyright © 2007 - 2008, Scott Thompson, All Rights Reserved
|
|
|
|
|