Permalink
Browse files

Add code for Files video

  • Loading branch information...
MattStopa committed Mar 27, 2012
1 parent e013fde commit d08028e7f9badf82d6c575baa3a75a09c8b6feee
@@ -0,0 +1 @@
+Hey this is one lineThis is another lineThis is a third line
@@ -0,0 +1,4 @@
+f = File.new("./my_file.txt", "w")
+f.puts("Hey this is a line")
+f.puts("This is a second line!")
+f.close
@@ -0,0 +1,5 @@
+lines = ["Hey this is one line", "This is another line", "This is a third line"]
+
+f = File.new("./my_file.txt", "w")
+lines.each { |line| f.puts(line) }
+f.close
@@ -0,0 +1,5 @@
+lines = ["Hey this is one line", "This is another line", "This is a third line"]
+
+f = File.new("./my_file.txt", "w")
+lines.each { |line| f.print(line) }
+f.close
@@ -0,0 +1,12 @@
+lines = []
+
+file = File.open("./sample.txt", "r")
+
+while (line = file.gets)
+ lines << line
+end
+
+file.close
+
+lines.each { |l| puts l }
+
@@ -0,0 +1,13 @@
+lines = []
+
+begin
+ file = File.open("./non-existant.txt", "r")
+ while (line = file.gets)
+ lines << line
+ end
+ file.close
+rescue => e
+ puts e
+end
+
+lines.each { |l| puts l }
@@ -0,0 +1,3 @@
+This is a great file.
+Lots of cool stuff here.
+Moooooooooooooooo!

0 comments on commit d08028e

Please sign in to comment.