private void copyFileFromClasspathToTargetDirectory( final String resourcePath, final File targetDirectory) throws IOException { FileOutputStream out = null; InputStream in = null; try { File resourceOnClasspath = new File(resourcePath); if (resourceOnClasspath.exists()) { in = new FileInputStream(resourceOnClasspath); } else { in = this.getClass().getClassLoader().getResourceAsStream(resourcePath); } File destinationFile = new File(targetDirectory, resourceOnClasspath.getName()); if (destinationFile.exists()) { return; } if (destinationFile.getParent() != null) { new File(destinationFile.getParent()).mkdirs(); } out = getOutputStreamForDestination(destinationFile); copyData(in, out); } finally { closeSafely(out, in); } }
private void copyFileFromClasspathToTargetDirectory( final String resourcePath, final File targetDirectory) throws IOException { FileOutputStream out = null; InputStream in = null; try { File resourceOnClasspath = new File(resourcePath); if (resourceOnClasspath.exists()) { in = new FileInputStream(resourceOnClasspath); } else { in = this.getClass().getClassLoader().getResourceAsStream(resourcePath); } File destinationFile = new File(targetDirectory, resourceOnClasspath.getName()); if (destinationFile.exists()) { return; } if (destinationFile.getParent() != null) { new File(destinationFile.getParent()).mkdirs(); } out = getOutputStreamForDestination(destinationFile); copyData(in, out); } finally { closeSafely(out, in); } }