How to read lines of a file in Ruby

后端 未结 8 1322
轮回少年
轮回少年 2020-12-02 04:16

I was trying to use the following code to read lines from a file. But when reading a file, the contents are all in one line:

line_num=0
File.open(\'xxx.txt\'         


        
8条回答
  •  情书的邮戳
    2020-12-02 04:43

    how about gets ?

    myFile=File.open("paths_to_file","r")
    while(line=myFile.gets)
     //do stuff with line
    end
    

提交回复
热议问题