Java URI to File Name getFile(URI uri)

Here you can find the source of getFile(URI uri)

Description

get File

License

Open Source License

Declaration

public static File getFile(URI uri) throws MalformedURLException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006-2007, Cloudsmith Inc.
 * The code, documentation and other materials contained herein have been
 * licensed under the Eclipse Public License - v 1.0 by the copyright holder
 * listed above, as the Initial Contributor under such license. The text of
 * such license is available at www.eclipse.org.
 ******************************************************************************/

import java.io.File;

import java.net.MalformedURLException;
import java.net.URI;

public class Main {
    public static File getFile(URI uri) throws MalformedURLException {
        if (uri == null)
            return null;

        String proto = uri.toURL().getProtocol();
        if (proto == null) {
            return new File(uri);
        } else if ("file".equalsIgnoreCase(proto)) //$NON-NLS-1$
        {// w ww.  j  ava2s .  co  m
            String path = uri.toString().replace("file:", "");
            return new File(path);
        }
        return null;
    }
}

Related

  1. getFile(java.net.URI uri)
  2. getFile(String ontURI)
  3. getFile(String uri)
  4. getFile(URI uri)
  5. getFile(URI uri)
  6. getFileByPathOrURI(String path)
  7. getFileFromURIList(URI[] uris, String fileName)
  8. getFilename(final URI uri)
  9. getFilename(final URI uri)