Java Path Convert To pathToFile(String f)

Here you can find the source of pathToFile(String f)

Description

given a filename, strip off the directory prefix (if any) and return it.

License

Open Source License

Declaration

public static String pathToFile(String f) 

Method Source Code

//package com.java2s;
/*//  w  w  w.  j ava 2s.c  o m
 * Copyright (C) 1990-2001 DMS Decision Management Systems Ges.m.b.H.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * $Id: Utils.java,v 1.5 2006-03-24 20:48:35 dimock Exp $
 */

public class Main {
    /**
     * given a filename, strip off the directory prefix (if any)
     *  and return it.  Return "./" if f has no dir prefix.
     */
    public static String pathToFile(String f) {
        String separator = System.getProperty("file.separator");
        int endOfPath = f.lastIndexOf(separator);

        if (endOfPath == -1) {
            // no path, use current directory
            return "." + separator;
        } else {
            return f.substring(0, endOfPath + 1);
        }
    }
}

Related

  1. pathToAdjacencyList(final int[] path, final int[] adjacencyList)
  2. pathToClassName(String path)
  3. pathToClassName(String pathName)
  4. pathToEmbedded(String relationType)
  5. pathToFields(String beanPath)
  6. pathToFullyQualifiedName(String classpath, String path)
  7. pathToName(String path)
  8. pathToName(String path, String fileName)
  9. pathTooLong()