Java File to URL fileToURL(File file)

Here you can find the source of fileToURL(File file)

Description

file To URL

License

Open Source License

Declaration

public static URL fileToURL(File file) 

Method Source Code


//package com.java2s;
/* uDig - User Friendly Desktop Internet GIS client
 * http://udig.refractions.net//from  w  w w .ja v a  2s. co m
 * (C) 2004-2011, Refractions Research Inc.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * (http://www.eclipse.org/legal/epl-v10.html), and the Refractions BSD
 * License v1.0 (http://udig.refractions.net/files/bsd3-v10.html).
 */

import java.io.File;

import java.io.IOException;

import java.net.MalformedURLException;

import java.net.URL;

public class Main {
    public static URL fileToURL(File file) {
        try {
            return file.toURI().toURL();
        } catch (MalformedURLException e) {
            try {
                return file.toURI().toURL();
            } catch (MalformedURLException e1) {
                try {
                    return new URL("file:/" + file.getCanonicalPath().replace('\\', '/')); //$NON-NLS-1$
                } catch (MalformedURLException e2) {
                    return null;
                } catch (IOException e2) {
                    return null;
                }
            }
        }
    }
}

Related

  1. fileToUrl(File file)
  2. FileToURL(File file)
  3. fileToURL(File file)
  4. fileToURL(File file)
  5. fileToURL(File file)
  6. fileToURL(File file)
  7. fileToURL(File file)
  8. fileToURL(File... files)
  9. fileToURL(String file)