# Changing the program to work with files

**URL:** <https://www.ruby-forum.com/t/changing-the-program-to-work-with-files/141085>\
**Category:** Ruby\
**Created:** [June 21, 2008, 8:30pm UTC](https://www.ruby-forum.com/t/changing-the-program-to-work-with-files/141085 "2008-06-21T20:30:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [June 21, 2008, 8:30pm UTC](https://www.ruby-forum.com/t/changing-the-program-to-work-with-files/141085/1 "2008-06-21T20:30:58Z")

</div>

Hi every body

I have a program that is working with Console ( input - output)

I wanted to see if anybody can help me to modify it so that it takes its  
input from a file (text) and write its output also to a file (binary)

because I am new to Ruby and I dunnot working with files .

Thank you very much

---

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [June 21, 2008, 9:02pm UTC](https://www.ruby-forum.com/t/changing-the-program-to-work-with-files/141085/2 "2008-06-21T21:02:29Z")

</div>

On Sat, Jun 21, 2008 at 10:29 PM, Alex Mr [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

which difference with file i/o and stdio that confuse you?

---

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [June 21, 2008, 9:15pm UTC](https://www.ruby-forum.com/t/changing-the-program-to-work-with-files/141085/3 "2008-06-21T21:15:20Z")

</div>

Hi, Thank you for reply .

May I ask you to help me modify the program to take input form files  
instead of Console ?

Can you please modify it for me ? if yes, Can I send the program to you  
to do this favor for me ?

---

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [June 22, 2008, 12:21pm UTC](https://www.ruby-forum.com/t/changing-the-program-to-work-with-files/141085/4 "2008-06-22T12:21:57Z")

</div>

Alex Mr wrote:

> I wanted to see if anybody can help me to modify it so that it takes its  
> input from a file (text) and write its output also to a file (binary)

Use the builtin File class.

---

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [June 23, 2008, 3:18pm UTC](https://www.ruby-forum.com/t/changing-the-program-to-work-with-files/141085/5 "2008-06-23T15:18:47Z")

</div>

Just change ARGV values with variables from file. This example do the  
work  
for 3 params taking them from command or file.

var1= ARGV[0]  
var2= ARGV[1]  
var3= ARGV[2]

file = ‘where\_is\_the\_file\_with\_param’

file\_with\_param =File.new(file,“r”)  
param = file\_with\_param.gets.split(’ ',-1)  
file\_with\_param.close()

var1 ||= param[0]  
var2 ||= param[1]  
var3 ||= param[2]

2008/6/22 Dave B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
