Jump to content

Read a file line by line: Difference between revisions

m
→‎{{header|Ruby}}: File.open automatically closes the file.
(→‎{{header|Ruby}}: Show how to open "|strange-name.txt".)
m (→‎{{header|Ruby}}: File.open automatically closes the file.)
Line 905:
end</lang>
 
''Caution!'' IO.foreach and File.foreach take a portname. To open an arbitrary filename (which might start with "|"), you must use File.open, then IO#each (or IO#each_line). The block form of File.open automatically closes the file after running the block.
 
<lang ruby>filename = "|strange-name.txt"
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.