How to specify output file encoding in Ruby?

Here’s an example that outputs a file in the UTF-16LE encoding:

open("data.txt", "w:UTF-16LE")

Ruby looks at the encoding of the string you are writing, and transcodes as necessary. Here’s a very detailed blog post describing mechanics with excellent examples (see the section called “The Default External and Internal Encodings”).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)