Java File Name Get getFilename(final String filenamePath)

Here you can find the source of getFilename(final String filenamePath)

Description

Retourniert Dateinamen ohne Pfad als String

License

Open Source License

Declaration

public static String getFilename(final String filenamePath) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

public class Main {
    public static String DIRECTORY_SEPARATOR = File.separator;

    /**/*from   w w w.j ava  2  s.co  m*/
     * Retourniert Dateinamen ohne Pfad als String
     */
    public static String getFilename(final String filenamePath) {
        String correctFilenamePath = getCorrectSeparators(filenamePath);

        if (correctFilenamePath.indexOf(DIRECTORY_SEPARATOR) < 0) {
            return filenamePath;
        }
        return correctFilenamePath.substring(correctFilenamePath.lastIndexOf(DIRECTORY_SEPARATOR) + 1,
                correctFilenamePath.length());
    }

    private static String getCorrectSeparators(final String pathOrFilename) {
        return pathOrFilename.replace("\\", DIRECTORY_SEPARATOR).replace("//", //$NON-NLS-1$ //$NON-NLS-2$
                DIRECTORY_SEPARATOR).replace("/", DIRECTORY_SEPARATOR); //$NON-NLS-1$
    }
}

Related

  1. getFilename(File file, boolean withExtension)
  2. getFileName(File path)
  3. getFileName(final File file)
  4. getFilename(final File file)
  5. getFileName(final File file)
  6. getFileName(final String p)
  7. getFilename(final String pPath)
  8. getFileName(final String subdirectory)
  9. getFilename(Locale locale, String fileName, String fileType)