Ruby“,不兼容的字符编码:UTF-8和CP852(Encoding :: CompatibilityError)” [英] Ruby, "incompatible character encodings: UTF-8 and CP852 (Encoding::CompatibilityError)"
本文介绍了Ruby“,不兼容的字符编码:UTF-8和CP852(Encoding :: CompatibilityError)”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么
# encoding: utf-8
out=File.open("z\\test.txt", "a")
out.puts "ç"
out.close
out=File.open("z\\test.txt", "r")
puts out.read+"ś"
导致不兼容的字符编码:UTF- 8和CP852(Encoding :: CompatibilityError)?
results in "incompatible character encodings: UTF-8 and CP852 (Encoding::CompatibilityError)"?
推荐答案
您的脚本在我的盒子上可以正常工作。
Your script works fine for me on my box.
您的终端应用程序或Ruby是否出现错误?
Is the error coming from your terminal application or from Ruby?
我的终端应用程序设置为使用utf -8。
My terminal app is set to use utf-8.
您可以通过在打开文件时明确提供编码来避免此问题。请参阅 http://www.ruby-doc.org/core/classes/ File.html#M000069 ,并遵循IO :: new的链接。
You can probably avoid this problem by explicitly supplying an encoding when opening your files. See http://www.ruby-doc.org/core/classes/File.html#M000069 and follow the links to IO::new.
这篇关于Ruby“,不兼容的字符编码:UTF-8和CP852(Encoding :: CompatibilityError)”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文