# How change encoding?

**URL:** <https://www.ruby-forum.com/t/how-change-encoding/181606>\
**Category:** Ruby\
**Created:** [January 14, 2010, 1:50pm UTC](https://www.ruby-forum.com/t/how-change-encoding/181606 "2010-01-14T13:50:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcelocavaco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e56c9b/32.png) [@marcelocavaco](https://www.ruby-forum.com/u/marcelocavaco)\
**Post date:** [January 14, 2010, 1:50pm UTC](https://www.ruby-forum.com/t/how-change-encoding/181606/1 "2010-01-14T13:50:36Z")

</div>

hi everybody,

please help…

i have a file (DocumentaÃ§Ã£o.txt) with this structure:

my\_data \<\< [0, “AÃ§Ã£o”, Zlib::Deflate.deflate(“Sample Text!!!”)].to\_a  
my\_data \<\< [0, “Test”, Zlib::Deflate.deflate(“Only ASCII  
chars!!!”)].to\_a  
my\_data \<\< [0, “Test char Ã”, Zlib::Deflate.deflate(“New test  
(Ã)”)].to\_a

OBS: i not create this file!!!

and i have this code:

require ‘fileutils’  
require ‘zlib’  
DestFile = “D:\temp\app\DocumentaÃ§Ã£o.txt”  
my\_read\_data = File.open(DestFile, ‘rb’) { |f| Marshal.load f }  
my\_read\_data.each do |item|  
file\_path = “D:\temp\app\new\_files\_” + item[1] + “.txt”  
file\_text = Zlib::Inflate.inflate(item[2])  
File.open(file\_path, ‘wb’) { |file| file.write(file\_text) }  
end

the result is

new\_files\_AÃ¾Ã’o.txt  
new\_files\_Test.txt  
new\_files\_Test char â”´.txt

and not

new\_files\_AÃ§Ã£o.txt  
new\_files\_Test.txt  
new\_files\_Test char Ã.txt

why this occurs?

is the encode???

how change ?

OBS: i do not create the file DocumentaÃ§Ã£o.txt. i only read it.

PS. be patient. i’m “very” newbiee in ruby.

---

<div class="post-metadata">

**Author:** ![marcelocavaco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e56c9b/32.png) [@marcelocavaco](https://www.ruby-forum.com/u/marcelocavaco)\
**Post date:** [January 14, 2010, 3:41pm UTC](https://www.ruby-forum.com/t/how-change-encoding/181606/2 "2010-01-14T15:41:14Z")

</div>

2010/1/14 Marcelo C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> (Ã)")].to\_a  
> Â file\_path = “D:\temp\app\new\_files\_” + item[1] + “.txt”  
> Â file\_text = Zlib::Inflate.inflate(item[2])  
> Â File.open(file\_path, ‘wb’) { |file| file.write(file\_text) }

I’d say you probably rather should open this file in text mode since  
you are looking at it in text mode - maybe with a particular encoding  
(see link below).

> new\_files\_AÃ§Ã£o.txt  
> new\_files\_Test.txt  
> new\_files\_Test char Ã.txt
> 
> why this occurs?
> 
> is the encode???

Likely.

> how change ?

James has an excellent blog posting about this:  
[http://blog.grayproductions.net/articles/miscellaneous\_m17n\_details](http://blog.grayproductions.net/articles/miscellaneous_m17n_details)

Kind regards

robert
