Created
May 29, 2012 23:40
-
-
Save maerzbow/2831484 to your computer and use it in GitHub Desktop.
read file with encoding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
file = File.open('iso-8859-1.txt', 'r:iso-8859-1') | |
puts file.external_encoding.name # >> ISO-8859-1 | |
file_content = file.read | |
puts file_content.encoding.name # >> ISO-8859-1 | |
file = File.open('iso-8859-1.txt', 'r:iso-8859-1:utf-8') | |
puts file.external_encoding.name # >> ISO-8859-1 | |
file_content = file.read | |
puts file_content.encoding.name # >> UTF-8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment