Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add code for Files video

  • Loading branch information...
commit d08028e7f9badf82d6c575baa3a75a09c8b6feee 1 parent e013fde
Matthew Stopa authored
1  files/1_open_closing/my_file.txt
... ... @@ -0,0 +1 @@
  1 +Hey this is one lineThis is another lineThis is a third line
4 files/1_open_closing/opening-writing-1.rb
... ... @@ -0,0 +1,4 @@
  1 +f = File.new("./my_file.txt", "w")
  2 +f.puts("Hey this is a line")
  3 +f.puts("This is a second line!")
  4 +f.close
5 files/1_open_closing/opening-writing-2.rb
... ... @@ -0,0 +1,5 @@
  1 +lines = ["Hey this is one line", "This is another line", "This is a third line"]
  2 +
  3 +f = File.new("./my_file.txt", "w")
  4 +lines.each { |line| f.puts(line) }
  5 +f.close
5 files/1_open_closing/opening-writing-3.rb
... ... @@ -0,0 +1,5 @@
  1 +lines = ["Hey this is one line", "This is another line", "This is a third line"]
  2 +
  3 +f = File.new("./my_file.txt", "w")
  4 +lines.each { |line| f.print(line) }
  5 +f.close
12 files/2_reading/reading_1.rb
... ... @@ -0,0 +1,12 @@
  1 +lines = []
  2 +
  3 +file = File.open("./sample.txt", "r")
  4 +
  5 +while (line = file.gets)
  6 + lines << line
  7 +end
  8 +
  9 +file.close
  10 +
  11 +lines.each { |l| puts l }
  12 +
13 files/2_reading/reading_2.rb
... ... @@ -0,0 +1,13 @@
  1 +lines = []
  2 +
  3 +begin
  4 + file = File.open("./non-existant.txt", "r")
  5 + while (line = file.gets)
  6 + lines << line
  7 + end
  8 + file.close
  9 +rescue => e
  10 + puts e
  11 +end
  12 +
  13 +lines.each { |l| puts l }
3  files/2_reading/sample.txt
... ... @@ -0,0 +1,3 @@
  1 +This is a great file.
  2 +Lots of cool stuff here.
  3 +Moooooooooooooooo!

0 comments on commit d08028e

Please sign in to comment.
Something went wrong with that request. Please try again.