title: Permission denied @ rb_sysopen (Errno :: EACCES) error when trying to execute Ruby program via RubyMine 2019.1
body: <p>I'm trying to execute a Ruby program <code>(Ruby v2.5.3)</code> on Windows 10 where I basically open a file <code>(sample1.txt, sample2.txt)</code> and append its contents (a list of 3 names) to an empty file <code>(result.txt)</code> and later sort the contents of file <code>result.txt</code> (entire code below). However, when I run this code on RubyMine 2019.1, I get an error as</p>
  
  <pre><code>Traceback (most recent call last):
          6: from C:/Users/tanveer.dey/RubymineProjects/src/Assignment9.rb:5:in `&lt;main&gt;'
          5: from C:/Users/tanveer.dey/RubymineProjects/src/Assignment9.rb:5:in `each'
          4: from C:/Users/tanveer.dey/RubymineProjects/src/Assignment9.rb:7:in `block in &lt;main&gt;'
          3: from C:/Users/tanveer.dey/RubymineProjects/src/Assignment9.rb:7:in `each'
          2: from C:/Users/tanveer.dey/RubymineProjects/src/Assignment9.rb:8:in `block (2 levels) in &lt;main&gt;'
          1: from C:/Users/tanveer.dey/RubymineProjects/src/Assignment9.rb:8:in `open'
  C:/Users/tanveer.dey/RubymineProjects/src/Assignment9.rb:8:in `initialize': Permission denied @ rb_sysopen - result.txt (Errno::EACCES)
  </code></pre>
  
  <p>All files have full permissions. However, when I execute the same code via the IRB terminal it works perfectly fine.</p>
  
  <p>I've just started working on Ruby and I couldn't find the solution to this problem anywhere. Your help is greatly appreciated.</p>
  
  <pre><code>file_array = ["sample1.txt", "sample2.txt"]
  
  file_array.each do |x|
    file = File.open(x,'r')
    file.each do |h|
    open('result.txt', 'a') do |f|
      puts f &lt;&lt; h
    end
    end
    open('result.txt','a') do |f|
      puts f &lt;&lt; "\n"
    end
    end
  
  new_array = File.readlines('result.txt').sort
  File.open('result.txt','w') do |file|
    new_array.each {|n| file.puts(n)}
  end
  </code></pre>