Java Path Is Absolute isAbsolute(String aPath)

Here you can find the source of isAbsolute(String aPath)

Description

Determine if the given String represents an absolute path by checking if the string starts with a '/' or is a URI that starts with a scheme 'scheme:/'.

License

Open Source License

Parameter

Parameter Description
aPath a parameter

Return

true if path is absolute, otherwise false.

Declaration

public static boolean isAbsolute(String aPath) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from w w  w  . ja  v  a  2 s .c  om
     * Determine if the given String represents an absolute path by
     * checking if the string starts with a '/' or
     * is a URI that starts with a scheme 'scheme:/'.
     *
     * @param aPath
     * @return true if path is absolute, otherwise false.
     */
    public static boolean isAbsolute(String aPath) {
        boolean absolute = false;
        String path = aPath.replace('\\', '/');
        // the path has a scheme if a colon appears before the first '/'
        if (path.indexOf(':') > 0 && path.indexOf('/') > path.indexOf(':')) {
            absolute = true;
        }
        // starts with a '/'
        else if (path.startsWith("/")) //$NON-NLS-1$
        {
            absolute = true;
        }

        return absolute;
    }
}

Related

  1. isAbsolute(final String path)
  2. isAbsolute(String path)
  3. isAbsolute(String path)
  4. isAbsolute(String path)
  5. isAbsolutePath(String filename)