unicode - 尝试在 Elixir 中将 unicode 字符写入文件时出现 no_translation 错误

标签 unicode erlang elixir latin1

我正在读取一个流,然后将其写入文件,但是我收到了由于 ' 的存在而导致的错误。我认为这是因为我打开的文件使用了错误的编码或其他内容,但我不知道如何正确设置它:

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/

相关文章:

c++ - 如何在 Windows 下使用 mingw 使用 ifstream 打开 unicode 文件?

java - 为什么 SPACE_SEPARATOR 类型的字符不被识别为空格?

transactions - Erlang/OTP 消息可靠吗?消息可以复制吗?

mysql - 具有可变参数的 Ecto 查询和自定义 MySQL 函数

range - 灵药字符范围

elixir - 如何让phoenix+ecto中的表单和事务玩的好?

mysql - 如何在 mysql 正则表达式中匹配大写字母ÅÄÖ

iphone - 如何在UIlabel中显示上标星号

erlang - 这两个代码块在功能上有什么区别?

scala - 构建基于 Actor 的系统的设计模式/最佳实践