File io 无法使用JRuby打开具有特殊字符的文件

File io 无法使用JRuby打开具有特殊字符的文件,file-io,encoding,jruby,File Io,Encoding,Jruby,下面的程序在ruby上运行得很好,但是当我访问一个带有特殊字符的文件时,JRuby出现了一个问题,比如我在测试中使用的名为“mão.txt”的文件: 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/RubyFi

下面的程序在ruby上运行得很好,但是当我访问一个带有特殊字符的文件时,JRuby出现了一个问题,比如我在测试中使用的名为“mão.txt”的文件:

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
我正在使用Ubuntu12.10、JRuby1.7.0和Java1.7.0\u09


我计划用Warble打包应用程序,所以我担心命令行参数不是一个选项。

这是一个用
Dir.glob
报告的错误,正如Sebastien所说,这是一个已知的错误

事实上,我找到了解决这个bug的方法。在本例中,我需要目录中的每个文件,而不是使用Dir.glob,我可以简单地使用Dir.entries,它工作正常

该程序可以更改为:

# coding: utf-8
path = File.expand_path(File.dirname(__FILE__))
puts "(A) #{__ENCODING__}"

puts "(B)" + "".encoding.to_s
puts "(C)" + String.new.encoding.to_s

dir = "#{path}/fixtures/"
entries = Dir.entries(dir) - ['.', '..']
entries.each do |f| 
    puts "(D)" + f.encoding.to_s + "  " + f
    file = "#{dir}/#{f}"
    puts "(E)" + file.encoding.to_s + "  " + file
    #f.encode("UTF-8")
    File.open(file)
    g = File.expand_path(file)
    puts "(F)" + g + " " + g.encoding.to_s
    File.open(g)
end
我已经为这个问题提交了一份报告,现在已经合并到核心中;因此,这个问题现在应该得到解决。
# coding: utf-8
path = File.expand_path(File.dirname(__FILE__))
puts "(A) #{__ENCODING__}"

puts "(B)" + "".encoding.to_s
puts "(C)" + String.new.encoding.to_s

dir = "#{path}/fixtures/"
entries = Dir.entries(dir) - ['.', '..']
entries.each do |f| 
    puts "(D)" + f.encoding.to_s + "  " + f
    file = "#{dir}/#{f}"
    puts "(E)" + file.encoding.to_s + "  " + file
    #f.encode("UTF-8")
    File.open(file)
    g = File.expand_path(file)
    puts "(F)" + g + " " + g.encoding.to_s
    File.open(g)
end