no_translation error while attempting to write unicode characters to file in Elixir
Asked Answered
S

1

8

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, "’")

Schrick answered 22/6, 2016 at 13:56 Comment(0)
B
16

You should open the file in :utf8 mode.

file = File.open!("/tmp/foo.txt", [:write, :utf8])
IO.write(file, "’")
Barthol answered 22/6, 2016 at 14:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.