「Ruby」open関数を使用してファイルを1行ずつ読み込む

構文
fp = open(“txtファイル名")
open関数を使用して、ファイルを1行ずつ読み込みます。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fp = open("test.txt")
fp.each do |line|
p line
end
fp.close
fp = open("test.txt") fp.each do |line| p line end fp.close
fp = open("test.txt")

fp.each do |line|
  p line
end

fp.close

 

Ruby

Posted by arkgame