public class FilenameUtil {
/*
* Java文件操作 获取文件扩展名
*
* Created on: 2011-8-2
* Author: blueeagle
*/
public static String getExtensionName(String filename) {
if ((filename != null) && (filename.length() > 0)) {
int dot = filename.lastIndexOf( '.' );
if ((dot > -1) && (dot < (filename.length() - 1))) {
return filename.substring( dot + 1 );
}
}
return filename;
}
/*
* Java文件操作 获取不带扩展名的文件名
*
* Created on: 2011-8-2
* Author: blueeagle
*/
public static String getFileNameNoEx(String filename) {
if ((filename != null) && (filename.length() > 0)) {
int dot = filename.lastIndexOf( '.' );
if ((dot > -1) && (dot < (filename.length()))) {
return filename.substring( 0, dot );
}
}
return filename;
}
/**
* 测试Demo
* @param args
*/
public static void main(String[] args) {
String filename = "xa.txt.gz";
System.out.println( getExtensionName( filename ) );
System.out.println( getFileNameNoEx( filename ) );
}
}
标签:文件,扩展名,String,filename,return,&&,Java,public,dot From: https://blog.csdn.net/qq_34931675/article/details/139503912