Ref:How to get file name without the extension?

Normally,there are two ways to implements this:use the library or the regular expression.

here I use the regular expression.

String s = "a.xml.ac.df.ef";
String result = s.replaceFirst("[.][^.]+$", "");
System.out.println(result);
  //outputs:a.xml.ac.df

以上是不考虑到Path, 若有Path,需要先截断路径分隔符,如:

/**获取文件的简短名称,如将"G:\\video_record\\eclipse\\promt-workspace-startup.lxe"转为
* "promt-workspace-startup"
* @param fileFullName 文件的完整路径.
* @return
*/
public static String getFileNameWithoutExtention(String fileFullName) {
//截断路径分隔符.
int backslash = fileFullName.lastIndexOf("\\") != -1 ? fileFullName.lastIndexOf("\\") : fileFullName.lastIndexOf("/");
int dot = fileFullName.lastIndexOf(".");
if (backslash > 0 && dot > 0) {
fileFullName = fileFullName.substring(backslash + 1, dot);
}
return fileFullName;
}
05-11 21:54