public static void resourceToFile ( String resourceName , File dest , Class src ) { InputStream is = null ; OutputStream os = null ; try { is = src . getClassLoader ( ) . getResourceAsStream ( resourceName ) ; if ( is == null ) { throw new RuntimeException ( "Could not load resource: " + resourceName ) ; } dest . getParentFile ( ) . mkdirs ( ) ; os = new FileOutputStream ( dest ) ; IOUtils . copy ( is , os ) ; } catch ( Exception e ) { throw new RuntimeException ( "Error copying resource '" + resourceName + "' to file '" + dest . getPath ( ) + "': " + e , e ) ; } finally { IOUtils . closeQuietly ( is ) ; IOUtils . closeQuietly ( os ) ; } }
Copy the given resource to the given file .