code: public static URL getUrlFor(final File aFile) throws IllegalArgumentException {
  
          // Check sanity
          Validate.notNull(aFile, "aFile");
  
          try {
              return aFile.toURI().normalize().toURL();
          } catch (MalformedURLException e) {
              throw new IllegalArgumentException("Could not retrieve the URL from file ["
                      + getCanonicalPath(aFile) + "]", e);
          }
      }
docs: Retrieves the URL for the supplied File. Convenience method which hides exception handling
  for the operation in question.
  
  @param aFile A File for which the URL should be retrieved.
  @return The URL for the supplied aFile.
  @throws java.lang.IllegalArgumentException if getting the URL yielded a MalformedURLException.