以下程序在 ruby 上运行良好,但在访问具有特殊字符(如我用于测试的文件,称为“mão.txt”)的文件时,JRuby 出现问题:
# coding: utf-8
puts "(A) #{__ENCODING__}"
puts "(B)" + "".encoding.to_s
puts "(C)" + String.new.encoding.to_s
Dir.glob("./fixtures/*").each do |f|
puts "(D)" + f.encoding.to_s + " " + f
File.open(f)
g = File.expand_path(f)
puts "(E)" + g + " " + g.encoding.to_s
File.open(g)
end
JRuby 的结果是:
(A) UTF-8
(B)UTF-8
(C)ASCII-8BIT
(D)ASCII-8BIT ./fixtures/mão.txt~
Errno::ENOENT: No such file or directory - ./fixtures/mão.txt~
initialize at org/jruby/RubyFile.java:315
open at org/jruby/RubyIO.java:1176
(root) at encoding.rb:10
each at org/jruby/RubyArray.java:1612
(root) at encoding.rb:8
我正在使用 Ubuntu 12.10、JRuby 1.7.0 和 java 1.7.0_09
我计划将应用程序与 Warble 一起打包,所以我担心命令行参数不是一个选项。