Here you can find the source of getFileNameFromPath(String str)
Parameter | Description |
---|
public static String getFileNameFromPath(String str)
//package com.java2s; //License from project: Open Source License import java.nio.file.Path; import java.nio.file.Paths; public class Main { /**//from w ww . j ava2 s .co m * parse the file name from file path string * * @param str:file path contains filename * @return file name */ public static String getFileNameFromPath(String str) { if (str == null || str.equals("") || str.isEmpty()) { return null; } Path p = Paths.get(str); String fileName = p.getFileName().toString(); return fileName; } public static String toString(double[] p, String token) { String s = ""; for (int i = 0; i < p.length; i++) { s += p[i] + token; } return s; } public static String toString(float[] p, String token) { String s = ""; for (int i = 0; i < p.length; i++) { s += p[i] + token; } return s; } public static String toString(long[] p, String token) { String s = ""; for (int i = 0; i < p.length; i++) { s += p[i] + token; } return s; } public static String toString(int[] p, String token) { String s = ""; for (int i = 0; i < p.length; i++) { s += p[i] + token; } return s; } public static String toString(short[] p, String token) { String s = ""; for (int i = 0; i < p.length; i++) { s += p[i] + token; } return s; } public static String toString(byte[] p, String token) { String s = ""; for (int i = 0; i < p.length; i++) { s += p[i] + token; } return s; } public static String toString(char[] p, String token) { String s = ""; for (int i = 0; i < p.length; i++) { s += p[i] + token; } return s; } public static String toString(boolean[] p, String token) { String s = ""; for (int i = 0; i < p.length; i++) { s += p[i] + token; } return s; } public static String toString(String[] p, String token) { String s = ""; for (int i = 0; i < p.length; i++) { s += p[i] + token; } return s; } /** * parse the file name from composite file structure/name * * @param str:file path contains filename * @return file name */ public static String getFileName(String str) { String extension = str.substring(str.lastIndexOf('.') + 1); String fileName = getFileNameFromPath(str); if (extension.equals(fileName)) { return fileName; } else { String ret = fileName.substring(0, fileName.lastIndexOf(extension) - 1); return ret; } } }