File input/output: Difference between revisions

m
→‎{{header|Ruby}}: Tweak descriptive test. Tell that IO.read(what, mode: 'rb') requires Ruby 1.9.
m ({{omit from|HTML}})
m (→‎{{header|Ruby}}: Tweak descriptive test. Tell that IO.read(what, mode: 'rb') requires Ruby 1.9.)
Line 1,531:
 
----
We can also copydo a fileIO with only the core languagelibrary.
 
<lang ruby>File.open('input.txt', 'rb') do |i|
Line 1,550:
But this has disadvantages:
 
* There was no 'b' flag, so it might not work with binary files on some platforms. With a 'b' flag, the code would be <code>open('output.txt', 'wb') {|f| f << IO.read('input.txt', mode: 'rb')}</code>, but this requires Ruby 1.9. (There is no way to pass 'b' flag to IO.read with Ruby 1.8.)
* If the file is verytoo large, we fail to allocate enough memory.
 
----
Anonymous user