title: AccessDeniedException in JUnit test using a TemporaryFolder
body: <p>I'm having an issue with a JUnit test I made. The method I'm testing takes an <code>InputStream</code> should throw an exception if the passed <code>InputStream</code> doesn't support mark/reset.</p>
  <p>The problem I am running into is that my test to ensure an exception gets thrown when an <code>InputStream</code> that doesn't support mark/reset gets passed (posted below) keeps throwing an <code>AccessDeniedException</code>.</p>
  <pre class="lang-java prettyprint-override"><code>public class IOTest{
  
      @Rule
      public TemporaryFolder tempFolder = TemporaryFolder()
  
      @Before
      public void createFolder() throws IOException {
          Files.createDirectories(tempFolder.getRoot().toPath().resolve(&quot;testFile&quot;));
      }
  
      @Test(expected = IllegalArgumentException.class)
      public void testDetectCharsetOnlyAcceptsMarkResetSupportedInputStreams() throws IOException {
          final Path testPath = tempFolder.getRoot().toPath().resolve(&quot;testFile&quot;);
          final InputStream testStream = Files.newInputStream(testPath);
          IO.detectCharset(testStream);
      }
  }
  </code></pre>
  <p>I think the problem I'm running into has to do with accessing the temporary folder, but I don't know how to circumvent this.</p>
  <p>Here is the stack trace that gets printed when I run this test:</p>
  <pre><code>java.lang.Exception: Unexpected exception, expected&lt;java.lang.IllegalArgumentException&gt; but was&lt;java.nio.file.AccessDeniedException&gt;
      at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:28)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
      at org.junit.rules.RunRules.evaluate(RunRules.java:20)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
      at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
      at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
      at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
      at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
      at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
      at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
  Caused by: java.nio.file.AccessDeniedException: C:\Users\antho\AppData\Local\Temp\junit4390480127201295432\testFile
      at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:83)
      at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
      at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
      at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:230)
      at java.nio.file.Files.newByteChannel(Files.java:361)
      at java.nio.file.Files.newByteChannel(Files.java:407)
      at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:384)
      at java.nio.file.Files.newInputStream(Files.java:152)
      at com.bunnell.anthony.booker.IOTest.testDetectCharsetOnlyAcceptsMarkResetSupportedInputStreams(IOTest.java:65)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:19)
      ... 24 more
  </code></pre>
  <p>I'm guessing it has something to do with permissions and the OS, but I'm just not sure how to get around this problem. If it helps, I'm using Windows 10.</p>