NASA666

不以物喜,不以己悲.
Posted on , viewed 479 times

日文Shift_JIS文件转UTF-8编码

# 日文Shift_JIS文件转utf-8编码
str = nil
File.open(filename, "r") do |f| 
  str = File.read(f,:encoding => Encoding::Shift_JIS).encode(Encoding::UTF_8)
end

newfilename = File.basename(filename,".txt") + "_utf8.txt"

File.open(newfilename,"a+") do |f|
  f.puts(str)
end