#!ruby # -*- mode: ruby; coding: utf-8 -*- # Last updated: <2016/10/24 00:21:09 +0900> # # UTF-16LE + BOM の文字列をテキストファイルとして出力 outfile = "_tmp.txt" File.open(outfile, 'wb:UTF-16LE') { |f| f.write "\uFEFF" # BOMを出力 DATA.each do |l| f.puts l.encode("UTF-16LE") end } __END__ ABCDEFG 0123456 日本語を記述