Java URL Value Check isLocalFile(URL url)

Here you can find the source of isLocalFile(URL url)

Description

is Local File

License

LGPL

Declaration

public static boolean isLocalFile(URL url) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.io.File;

import java.net.URI;
import java.net.URL;

public class Main {
    private static final String FILE_SCHEME = "file";

    public static boolean isLocalFile(URL url) {
        try {//from  w w  w  .j  a v a 2  s  .  c  om
            if (url.getProtocol().equals(
                    new File(url.getFile()).toURI().toURL().getProtocol())) {
                return true;
            }
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return false;
    }

    public static boolean isLocalFile(URI uri) {
        try {
            if (uri.isAbsolute() && !uri.isOpaque()
                    && FILE_SCHEME.equals(uri.getScheme())) {
                return true;
            }
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return false;
    }
}

Related

  1. isLegalURL(final String url)
  2. isLocal(URL aURL)
  3. isLocalFile(URL url)
  4. isLocalFile(URL url)
  5. isLocalFile(URL url)
  6. isLocalFile(URL url)
  7. isLocalhost(URL url)
  8. isLocalURL(String s)
  9. isLocalURL(URL url)