Changes

Jump to: navigation, search

Working with Files in Ruby

6 bytes removed, 13:22, 1 December 2007
no edit summary
In the previous chapter we looked at how to work with directories. This chapter we will look in detail at how to create, open and read and write to files in Ruby. We will then learn how to delete and rename files.
== Creating a New File with Ruby ==
New files are created in Ruby using the ''new'' method of the ''File'' class. The ''new'' method accepts two arguments, the first being the name of the file to be created and the second being the mode in which the file is to opened. Supported file modes are shown the following table:
<table border="1" cellspacing="0" width="100%">
</pre>
Finally, find out the creatationcreate, modify and access times with ''ctime'', ''mtime'' and ''atime'':
<pre>
</pre>
It is also possible to extract data from a file on a character by character basis using the ''getc'' method:
<pre>

Navigation menu