【问题标题】:no_translation error while attempting to write unicode characters to file in Elixir尝试将 unicode 字符写入 Elixir 中的文件时出现 no_translation 错误
【发布时间】:2016-10-24 12:36:21
【问题描述】:

我有一个正在读取并写入文件的流,但是我收到了一个由’ 的存在引起的错误。我认为这是因为我打开文件时使用了错误的编码或其他东西,但我不知道如何正确设置它:

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

这会导致以下错误:

** (ErlangError) erlang 错误: :no_translation (stdlib) :io.put_chars(#PID, :unicode, "'")

【问题讨论】:

    标签: unicode erlang elixir latin1


    【解决方案1】:

    您应该以:utf8 模式打开文件。

    file = File.open!("/tmp/foo.txt", [:write, :utf8])
    IO.write(file, "’")
    

    【讨论】:

      猜你喜欢
      • 2018-02-18
      • 1970-01-01
      • 2011-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多