java 文件名截取方法
程序员文章站
2023-12-03 13:35:52
1.截取不带后缀的文件名 string resourcename=resourcesearchbean.getfilename(); if(stringhelper.isn...
1.截取不带后缀的文件名
string resourcename=resourcesearchbean.getfilename();
if(stringhelper.isnotempty(resourcename)&&resourcename.length()>0);
{
int dot = resourcename.lastindexof('.');
if ((dot >-1) && (dot < (resourcename.length()))) {
return resourcename.substring(0, dot);
}
}
2.截取文件后缀名
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;
}
string resourcename=resourcesearchbean.getfilename();
if(stringhelper.isnotempty(resourcename)&&resourcename.length()>0);
{
int dot = resourcename.lastindexof('.');
if ((dot >-1) && (dot < (resourcename.length()))) {
return resourcename.substring(0, dot);
}
}
2.截取文件后缀名
复制代码 代码如下:
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;
}