Here you can find the source of isRelativePath(String fileName)
Parameter | Description |
---|---|
fileName | The file name. |
boolean
value indicating if the file name contains relative path or not.
public static boolean isRelativePath(String fileName)
//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; } }