Java File Name Extract extractFileName(String filePathName)

Here you can find the source of extractFileName(String filePathName)

Description

extract File Name

License

Open Source License

Declaration

public static String extractFileName(String filePathName) 

Method Source Code

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

public class Main {
    public static String extractFileName(String filePathName) {
        if (filePathName == null) {
            return null;
        }// w  w w .j  a va2 s.co  m
        int dotPos = filePathName.lastIndexOf('.');
        int slashPos = filePathName.lastIndexOf('\\');
        if (slashPos == -1) {
            slashPos = filePathName.lastIndexOf('/');
        }
        if (dotPos > slashPos) {
            return filePathName.substring(slashPos > 0 ? slashPos + 1 : 0, dotPos);
        }
        return filePathName.substring(slashPos > 0 ? slashPos + 1 : 0);
    }
}

Related

  1. extractFileName(final String filePath)
  2. extractFileName(StackTraceElement aFrame)
  3. extractFileName(String file)
  4. extractFileName(String fileName)
  5. extractFileName(String filePathName)
  6. extractFileName(String fn)
  7. extractFileName(String fullPath)
  8. extractFileName(String name)
  9. extractFilename(String path)