# File lib/inifile.rb, line 76
  def write( filename = nil, opts={} )
    @fn = filename unless filename.nil?

    encoding = opts[:encoding] || @encoding
    mode = (RUBY_VERSION >= '1.9' && @encoding) ?
         "w:#{encoding.to_s}" :
         'w'

    File.open(@fn, mode) do |f|
      @ini.each do |section,hash|
        f.puts "[#{section}]"
        hash.each {|param,val| f.puts "#{param} #{@param} #{val}"}
        f.puts
      end
    end
    self
  end