Java File Name Get getFileName(String name)

Here you can find the source of getFileName(String name)

Description

get File Name

License

Open Source License

Declaration

public static String getFileName(String name) 

Method Source Code

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

import java.io.File;

public class Main {
    public static String getFileName(String name) {
        if (new File(name).exists()) {
            return name;
        }/*from  ww w. jav  a  2 s . c  o  m*/

        if (System.getProperty("os.name").contains("Mac")) {
            try {
                String appBundle = (String) Class.forName("com.apple.eio.FileManager")
                        .getMethod("getPathToApplicationBundle", (Class[]) null).invoke(null, (Object[]) null);
                if (new File(appBundle + "/Contents/Resources/Java/" + name).exists()) {
                    return appBundle + "/Contents/Resources/Java/" + name;
                }
            } catch (Exception e) {
                //fail quietly
            }
        }

        return "";
    }
}

Related

  1. getFileName(String filePath)
  2. getFileName(String filePath)
  3. getFileName(String folder, final String path)
  4. getFilename(String fullFilename)
  5. getFileName(String localRootDirName, String ending)
  6. getFileName(String originPath)
  7. getFilename(String path)
  8. getFileName(String path)
  9. getFileName(String path)