title: How to copy file into another directory in Java 8?
body: <p>I want to copy file from one package to another package.</p>
  <p>I tried <code>Files.copy</code> method but it replaces my folder with copied file.</p>
  <pre><code>public static void main(String[] args) throws IOException {
  
      InputStream in = CopyFileToDirectoryTest.class.getClassLoader()
              .getResourceAsStream(&quot;com/stackoverflow/main/Movie.class&quot;);
  
      Path path = Paths.get(&quot;D://folder&quot;);
  
      long copy = Files.copy(in, path,StandardCopyOption.REPLACE_EXISTING);
      System.out.println(copy);
  
  }
  </code></pre>
  <p>This doesn't work because it deletes folder and creates file with the name of folder.</p>
  <p>Is there a way in Java 8 or I should use <a href="https://commons.apache.org/proper/commons-io/" rel="nofollow noreferrer">Apache Commons IO</a>?</p>