title: Force IOException during file reading
body: <p>I have a piece of code that reads data from a file. I want to force IOException in this code for testing purposes (I want to check if the code throws a correct custom exception in this case).</p>
  
  <p>Is there any way to create a file which is protected from being read, for example? Maybe dealing with some security checks can help? </p>
  
  <p>Please, note that passing the name of a non-existent file cannot help, because FileNotFoundException has a separate catch clause.</p>
  
  <p>Here is the piece of code for better understanding of the question:</p>
  
  <pre><code>    BufferedReader reader = null;
      try {
  
          reader = new BufferedReader(new FileReader(csvFile));
  
          String rawLine;
          while ((rawLine = reader.readLine()) != null) {
              // some work is done here
          }
  
      } catch (FileNotFoundException e) {
          throw new SomeCustomException();
      } catch (IOException e) {
          throw new SomeCustomException();
      } finally {
          // close the input stream
          if (reader != null) {
              try {
                  reader.close();
              } catch (IOException e) {
                  // ignore
              }
          }
      }
  </code></pre>