From: Robert Klemme Date: 2009-09-21T22:05:16+09:00 Subject: Re: How to create a file with UTF-8 encoding 2009/9/21 Jin Lee : > Hi, as known that the default encoding is set to ANSI when creating a > text file.  How can I specify the encoding type to UTF-8 other than ANSI > when creating a text file in RUBY?  Thanks a lot. > > I've tried the ways found by google, but no available.  E.g. > tst = File.new("abc.txt","w:UTF-8") > There is an error message: illegal access mode w:UTF-8 (ArgumentError) You did not mention your Ruby version. I do not see your error: 15:03:23 tmp$ allruby -e 'File.open("x", "w:UTF-8") {|io| io.write("hello")}' CYGWIN_NT-5.1 padrklemme1 1.5.25(0.156/4/2) 2008-06-12 19:34 i686 Cygwin ======================================== ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin] -e:1: warning: encoding options not supported in 1.8: w:UTF-8 ======================================== ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-cygwin] 15:04:07 tmp$ allruby -e 'File.open("x", "wb:UTF-8") {|io| io.write("hello")}' CYGWIN_NT-5.1 padrklemme1 1.5.25(0.156/4/2) 2008-06-12 19:34 i686 Cygwin ======================================== ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin] -e:1: warning: encoding options not supported in 1.8: wb:UTF-8 ======================================== ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-cygwin] 15:04:15 tmp$ Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/