watir学习系列--文件操作(读取文件)

filepath ="c:\\flightlist.txt"


class FileToRow
  #获取文件内容,以数组的方式返回
  def getFileData(path)
    @@path = path
    @@str,@@file,@@rows,@@row  = '','',[],''
    @@file = File.open(@@path)
    @@row  = @@file.readlines
    @@row.each do |x|
        x = x.strip         #去除每行后的换行字符:\n
        x = x.split(',')    #将字符转换为数组
        @@rows << x         #数组追加
    end   
   return @@rows
  end
end
FileToRow = FileToRow.new
file_row = FileToRow.getFileData(filepath)  #获取文件内容
puts file_row.to_s

posted @ 2008-08-27 17:17  赵献良  阅读(755)  评论(5编辑  收藏  举报