Java File Name Extract extractFileName(String path)

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

Description

extract File Name

License

Open Source License

Declaration

public static String extractFileName(String path) 

Method Source Code

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

public class Main {
    public static String extractFileName(String path) {
        int index = path.lastIndexOf("\\");

        if (index > -1) {
            if (index < path.length() - 1) {
                return path.substring(index + 1);
            } else {
                return "";
            }//from  w w  w .  j  av  a 2 s. co  m
        }

        index = path.lastIndexOf("/");

        if (index > -1) {
            if (index < path.length() - 1) {
                return path.substring(index + 1);
            } else {
                return "";
            }
        }

        return path;
    }
}

Related

  1. extractFileName(String filePathName)
  2. extractFileName(String fn)
  3. extractFileName(String fullPath)
  4. extractFileName(String name)
  5. extractFilename(String path)
  6. extractFileName(String path)
  7. extractFileName(String path)
  8. extractFilename(String path)
  9. extractFileName(String url)