Skip to content

Instantly share code, notes, and snippets.

@stungeye
Created March 29, 2010 14:36
Show Gist options
  • Save stungeye/347891 to your computer and use it in GitHub Desktop.
Save stungeye/347891 to your computer and use it in GitHub Desktop.
Ruby Read File By Line
# Ruby Read File By Line
WORKING_DIR = File.dirname(__FILE__)
File.foreach(WORKING_DIR + '/filename.txt') do |line|
puts line
end
# The file can be online too
require 'open-uri'
open('http://stungeye.com') do |f|
f.each_line { |l| puts l }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment