code: private static void writeResourceToFile(
          String resourceName, File file) throws IOException
      {
          if (file == null)
          {
              throw new NullPointerException("Target file may not be null");
          }
          if (file.exists())
          {
              throw new IllegalArgumentException(
                  "Target file already exists: "+file);
          }
          InputStream inputStream = 
              LibUtils.class.getResourceAsStream(resourceName);
          if (inputStream == null)
          {
              throw new IOException(
                  "No resource found with name '"+resourceName+"'");
          }
          OutputStream outputStream = null;
          try
          {
              outputStream = new FileOutputStream(file);
              byte[] buffer = new byte[32768];
              while (true)
              {
                  int read = inputStream.read(buffer);
                  if (read < 0)
                  {
                      break;
                  }
                  outputStream.write(buffer, 0, read);    
              }
              outputStream.flush();
          }
          finally 
          {
              if (outputStream != null)
              {
                  try
                  {
                      outputStream.close();
                  }
                  catch (IOException e)
                  {
                      logger.log(Level.SEVERE, e.getMessage(), e);
                  }
              }
              try
              {
                  inputStream.close();
              }
              catch (IOException e)
              {
                  logger.log(Level.SEVERE, e.getMessage(), e);
              }
          }
      }
docs: Obtain an input stream to the resource with the given name, and write
  it to the specified file (which may not be <code>null</code>, and
  may not exist yet)
  
  @param resourceName The name of the resource
  @param file The file to write to
  @throws NullPointerException If the given file is <code>null</code>
  @throws IllegalArgumentException If the given file already exists
  @throws IOException If an IO error occurs