Java Path File Name nio fileName(final Path thePath)

Here you can find the source of fileName(final Path thePath)

Description

file Name

License

Open Source License

Declaration

public static String fileName(final Path thePath) 

Method Source Code

//package com.java2s;
/*/*from w  w  w  .j a  v  a2 s  . c  o  m*/
 * Copyright (c) 2013 christianr.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v3
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-3.0.html
 * 
 * Contributors:
 *     christianr - initial API and implementation
 */

import java.nio.file.FileSystems;

import java.nio.file.Path;

public class Main {
    /**
     * Gets the name of the given file without an extension.
     * @param theFile path to get the name
     * @return name of the given file without an extension.
     */
    public static String fileName(final String theFile) {
        int myIndex = theFile.lastIndexOf('.');
        final int mySeperator = theFile.lastIndexOf(FileSystems
                .getDefault().getSeparator());
        if (myIndex < mySeperator)
            myIndex = -1;
        if (myIndex < 0)
            return theFile.substring(Math.max(0, mySeperator));
        return theFile.substring(Math.max(0, mySeperator), myIndex);
    }

    public static String fileName(final Path thePath) {
        return fileName(thePath.getFileName().toString());
    }
}

Related

  1. concatFileName(String fileName, Path pathLocation)
  2. convertFilePathToName(Path file)
  3. detectFilePath(String propertyName, String confFileName)
  4. endsWith(File file, String pathname)
  5. fileName(final Path path)
  6. filterJarContainingClass(Collection jarsPaths, String className)
  7. findExecutablePaths(String executableName)
  8. findFile(Path directoryPath, String fileName)
  9. findFile(String basePath, final String fileName)