1) No matter what you do, there can always be an invalid byte sequence.
2) You have to know the encoding of a file to read it.

#encoding: utf-8

puts RUBY_VERSION

str = "m, ”ļou"

File.open('text.txt', 'w') do |f|
  f.puts str
end

IO.foreach('text.txt', 'r') do |line|
  p line.encoding.name
  p line
end


--output:--
1.9.2
"UTF-8"
"m, ”ļou\n"