Java Path File Name nio getFileName(Path path)

Here you can find the source of getFileName(Path path)

Description

Root path have no file name.

License

Open Source License

Parameter

Parameter Description
path a parameter

Return

file name

Declaration

public static String getFileName(Path path) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * File: PathUtils.java//from w  w w.j a v  a 2s.com
 * 
 * Date: 2014/08/11
 * Author: Mikhail Niedre
 * 
 * Copyright (c) 2014 Original authors and others.
 * 
 * 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
 * <a href="http://www.eclipse.org/legal/epl-v10.html">epl-v1.0</a>
 *
 * Contributors:
 * Mikhail Niedre - initial API and implementation
 *******************************************************************************/

import java.nio.file.Path;

public class Main {
    /**
     * Root path have no file name.
     * 
     * TODO rework extra symbols
     * 
     * @param path
     * @return file name
     */
    public static String getFileName(Path path) {
        String pathString = null;
        if (path != null) {
            if (path.getFileName() != null) {
                pathString = path.getFileName().toString();
            } else {
                pathString = path.toString();
            }
        }
        return pathString;
    }
}

Related

  1. getFileContent(String fileNameOrPath)
  2. getFileInFolder(Path p, String filename)
  3. getFilename (final String filepath)
  4. getFilename(final Path path)
  5. getFilename(final Path path)
  6. getFileName(Path path)
  7. getFileName(String fullPath, boolean withParentFolder)
  8. getFileName(String path)
  9. getFileName(String relativePath)