# Importing text files - file type (UTF-16 for instance)

**URL:** <https://www.ruby-forum.com/t/importing-text-files-file-type-utf-16-for-instance/157879>\
**Category:** Rails\
**Created:** [January 16, 2009, 8:06am UTC](https://www.ruby-forum.com/t/importing-text-files-file-type-utf-16-for-instance/157879 "2009-01-16T08:06:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeffpritchard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/43a26b/32.png) [@jeffpritchard](https://www.ruby-forum.com/u/jeffpritchard)\
**Post date:** [January 16, 2009, 8:06am UTC](https://www.ruby-forum.com/t/importing-text-files-file-type-utf-16-for-instance/157879/1 "2009-01-16T08:06:44Z")

</div>

Hi,  
I’m using the iFrame and responds\_to\_parent method to import some text  
files (csv files) from various sources. Some of the files of interest  
are in UTF-8 or UTF-16 format.

How can my code determine what the file type is of an imported file?  
How can I convert a file from UTF-16 to a 7 or 8 bit file (for now at  
least, I’m not required to deal with languages that actually need 16  
bits.) GMail, for instance, exports UTF-16 files, even if the contents  
are all English or other 8 bit languages.

So when I import one, I get alternating ascii chars and diamond with a  
question mark in the middle chars (I assume that’s how my Mac displays  
an ascii NULL.

I suppose I could snoop the type from the gathered data by looking for  
the alternating null chars, but that seems really cheesy.

thanks!

jp
