下面的程序適用於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)這個問題是現在已經合併成核心;所以現在問題應該得到解決。 –