Java Is Relative Path isRelative(final String path)

Here you can find the source of isRelative(final String path)

Description

Determine whether a path name is relative.

License

Open Source License

Parameter

Parameter Description
path the path name

Return

true if it is relative

Declaration

public static boolean isRelative(final String path) 

Method Source Code


//package com.java2s;
/*//ww  w . j  a va  2s .  c  o m
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.File;

public class Main {
    /**
     * Determine whether a path name is relative.
     *
     * @param path the path name
     * @return {@code true} if it is relative
     */
    public static boolean isRelative(final String path) {
        return path.isEmpty() || !isSeparator(path.charAt(0));
    }

    /**
     * Determine whether the given character is a {@code /} or a platform-specific separator.
     *
     * @param ch the character to test
     * @return {@code true} if it is a separator
     */
    public static boolean isSeparator(final char ch) {
        // the second half of this compare will optimize away on / OSes
        return ch == '/' || File.separatorChar != '/' && ch == File.separatorChar;
    }
}

Related

  1. isRelative(File target_)
  2. isRelative(String path)
  3. isRelativePath(final String filePath)
  4. isRelativePath(String candidatePath)
  5. isRelativePath(String fileName)