TOC
Java file-name, ,file pathfrom (e.g. time, place, numerical quantity)(filename) extensionRetrieve the
Java.file-namefrom (e.g. time, place, numerical quantity)(filename) extensionThe following is a sample source to obtain
sample program
/** * @param fileName returns the file extension from the filename. * @param fileName file name * @return file extension */ public static String getSuffix(String fileName) { if (fileName == null) return null; int point = fileName.lastIndexOf(".") ; if (point ! = -1) { return fileName.substring(point + 1); } } return fileName; } }
Execution Result
◆Example of Execution
/** * Execution example * @param args */ public static void main(String[] args) { String ret1 = getSuffix("test.html"); System.out.println(ret1); String ret2 = getSuffix("C:\\test.html"); System.out.println(ret2); }
◆Output result
html html