Utility to convert File to URL. : URI « Network Protocol « Java






Utility to convert File to URL.

       
/*
 * JBoss DNA (http://www.jboss.org/dna)
 * See the COPYRIGHT.txt file distributed with this work for information
 * regarding copyright ownership.  Some portions may be licensed
 * to Red Hat, Inc. under one or more contributor license agreements.
 * See the AUTHORS.txt file in the distribution for a full listing of 
 * individual contributors. 
 *
 * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
 * is licensed to you under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * JBoss DNA is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

public class FileMonitor {

  /**
   * Utility to convert {@link File} to {@link URL}.
   * 
   * @param filePath the path of the file
   * @return the {@link URL} representation of the file.
   * @throws MalformedURLException
   * @throws IllegalArgumentException if the file path is null, empty or blank
   */
  public static URL convertFileToURL( String filePath ) throws MalformedURLException {
     
      File file = new File(filePath.trim());
      return file.toURI().toURL();
  }
}

   
    
    
    
    
    
    
  








Related examples in the same category

1.Encode a URI path
2.Add two URI path segments
3.Remove parameters from a uri.
4.Remove any authorisation details from a URI
5.A class to represent a Uniform Resource Identifier (URI).
6.Return True if the uri has a scheme
7.Normalize a uri containing ../ and ./ paths.
8.URI Support
9.URI utilities
10.Get Parent URI
11.Create and resolve URI
12.Add parameters stored in the Map to the uri string.
13.Make a URL from the given string
14.Is Equal URI
15.Resolves the specified URI, and returns the file represented by the URI.
16.Returns the filename for the specified URI.