Java Is Relative Path isRelativePath(String fileName)

Here you can find the source of isRelativePath(String fileName)

Description

Checks if a given file name contains relative path.

License

Open Source License

Parameter

Parameter Description
fileName The file name.

Return

A boolean value indicating if the file name contains relative path or not.

Declaration

public static boolean isRelativePath(String fileName) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004,2008 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://w w w  .  j  a  v  a 2s . c  o  m
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

import java.io.File;

public class Main {
    /**
     * Checks if a given file name contains relative path.
     * 
     * @param fileName
     *            The file name.
     * @return A <code>boolean</code> value indicating if the file name
     *         contains relative path or not.
     */
    public static boolean isRelativePath(String fileName) {
        if (fileName == null || fileName.indexOf(':') > 0 || fileName.startsWith("\\\\")) //$NON-NLS-1$
        {
            return false;
        }

        if (File.separatorChar == '/') {
            // Linux
            return !fileName.startsWith(File.separator);
        } else if (File.separatorChar == '\\') {
            // Windows
            File file = new File(fileName);
            return !file.isAbsolute();
        }

        return false;
    }
}

Related

  1. isRelative(File target_)
  2. isRelative(final String path)
  3. isRelative(String path)
  4. isRelativePath(final String filePath)
  5. isRelativePath(String candidatePath)
  6. isRelativePath(String path)
  7. isRelativePath(String path)
  8. isRelativePath(String path)
  9. isRelativePath(String path)