public static void copyResourceToFile ( String resourceAbsoluteClassPath , File targetFile ) throws IOException { InputStream is = ResourceUtil . class . getResourceAsStream ( resourceAbsoluteClassPath ) ; if ( is == null ) { throw new IOException ( "Resource not found! " + resourceAbsoluteClassPath ) ; } OutputStream os = null ; try { os = new FileOutputStream ( targetFile ) ; byte [ ] buffer = new byte [ 2048 ] ; int length ; while ( ( length = is . read ( buffer ) ) != - 1 ) { os . write ( buffer , 0 , length ) ; } os . flush ( ) ; } finally { try { is . close ( ) ; if ( os != null ) { os . close ( ) ; } } catch ( Exception ignore ) { // ignore } } }
Copy resources to file system .