下面的程序适用于ruby,但在到达带有特殊字符(如我用于测试的文件,名为“mão.txt”)的文件时,给我带来了JRuby问题:使用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
我打算有战争打包的应用程序ble,所以我担心命令行参数不是一个选项。
我已经提交[补丁](https://github.com/jruby/jruby/pull/407)这个问题是现在已经合并成核心;所以现在问题应该得到解决。 –