Java Path Is Absolute isAbsolutePath(String path)

Here you can find the source of isAbsolutePath(String path)

Description

is Absolute Path

License

Open Source License

Declaration

public static boolean isAbsolutePath(String path) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static boolean isAbsolutePath(String path) {
        // On Windows, we cannot just ask if the file name starts with file
        // separator.
        // If path contains ":" at the second position, then it is not relative,
        // I guess.
        // However, if it starts with separator, then it is absolute too.

        // Possible problems: Not tested on Macintosh, but should work.
        // Koh, 1.4.2004: Resolved problem: I tested on Mac OS X 10.3.3 and
        // worked.

        String osNameStart = System.getProperty("os.name").substring(0, 3);
        String fileSeparator = System.getProperty("file.separator");
        if (osNameStart.equals("Win")) {
            return ((path.length() > 1) && path.substring(1, 2).equals(":")) || path.startsWith(fileSeparator);
        } else if (osNameStart.equals("Mac")) {
            // Koh:Panther (or Java 1.4.2) may change file path rule
            return path.startsWith(fileSeparator);
        } else {//from   w  w w . j  a  va 2  s.com
            return path.startsWith(fileSeparator);
        }
    }
}

Related

  1. isAbsolute(String path)
  2. isAbsolutePath(String filename)
  3. isAbsolutePath(String path)
  4. isAbsolutePath(String path)
  5. isAbsolutePath(String path)
  6. isAbsolutePath(String path)
  7. isAbsolutePath(String path)
  8. isAbsolutePath(String path)
  9. isAbsolutePath(String path)