7

I have a stream that I'm reading from and in turn am writing to a file however I am getting an error that is caused by the presence of a . I assume this is because I'm opening the file w/ the wrong encoding or something but I don't know how to properly set it:

file = File.open!("/some/path.csv", [:write])
IO.write(file, "’")

This results in the following error:

** (ErlangError) erlang error: :no_translation (stdlib) :io.put_chars(#PID<0.250.0>, :unicode, "’")

tom
  • 18,953
  • 4
  • 35
  • 35
Kyle Decot
  • 20,715
  • 39
  • 142
  • 263

1 Answers1

16

You should open the file in :utf8 mode.

file = File.open!("/tmp/foo.txt", [:write, :utf8])
IO.write(file, "’")
tom
  • 18,953
  • 4
  • 35
  • 35