我正在读取一个流,然后将其写入文件,但是我收到了由于 '
的存在而导致的错误。我认为这是因为我打开的文件使用了错误的编码或其他内容,但我不知道如何正确设置它:
file = File.open!("/some/path.csv", [:write])
IO.write(file, "’")
这会导致以下错误:
** (ErlangError) erlang error: :no_translation (stdlib) :io.put_chars(#PID<0.250.0>, :unicode, "’")
最佳答案
您应该以 :utf8
模式打开文件。
file = File.open!("/tmp/foo.txt", [:write, :utf8])
IO.write(file, "’")
关于unicode - 尝试在 Elixir 中将 unicode 字符写入文件时出现 no_translation 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37970230/