[Tut] Printing the File Contents - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18) +---- Forum: Ruby and Ruby on Rails (https://www.supportforums.net/forumdisplay.php?fid=55) +---- Thread: [Tut] Printing the File Contents (/showthread.php?tid=4364) |
[Tut] Printing the File Contents - Jordan L. - 01-15-2010 G'day everyone. Today I'll explain how to make a "Print File Contents" Script. Where it simple prints all the contents (The text) of what's in a file. 1. The Code Code: ############################################################################ 2. Explaining the Code Now I don't really want to waste time with the #! /usr/bin/env ruby and basic things such as puts("Blah") or gets.chomp!, because you should know what they're if you've been reading my other tutorials. So I'll jump ahead to the Error Handling and IO.read code. IO.read(file) In the code, you would've seen something like: Code: print file_contents = IO.read(file) For example: I ran the above script, and made it read a HTML document on my Desktop, here was the input / output: Code: jordan@ModernWarfare ~/Desktop/Ruby $ ruby reader.rb Error Handling As I've explained in most of my Tutorials, error handling is a must have if you plan on releasing your software / scripts that you make. It helps you as the Developer, and They as the Customers out alot. For more explanation on the Error Handling code, please use my other tutorials as a guide. "File Writer" Tut has it explained in full. Thanks for Reading and I hope I helped you out -Jordan. RE: [Tut] Printing the File Contents - leryn17 - 11-05-2010 I am not familiar in printing the file contents. In fact, your tutorial would be a great help for it. I am actually conscious before on how to print file contents, but fortunately, it was just simple then. RE: [Tut] Printing the File Contents - SlimDeath - 11-16-2010 Thanks for the tutorial mate. It will be useful for many people. RE: [Tut] Printing the File Contents - Preeminent - 11-24-2010 Great tutorial, should come in handy for some people. RE: [Tut] Printing the File Contents - Diabolic - 11-28-2010 Thanks this is very helpful RE: [Tut] Printing the File Contents - xKroNiiK - 12-01-2010 Thanks for the TUT. RE: [Tut] Printing the File Contents - Bursihido - 12-11-2010 Good job Thanks RE: [Tut] Printing the File Contents - Ɲymph - 12-12-2010 Thanks for the usefull tutorial. Really well explained, thanks! RE: [Tut] Printing the File Contents - Distant Relatives - 12-12-2010 Great tutorial, very useful for me . thanks |