java 文件名截取方法
程序员文章站
2024-02-06 11:15: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;
}
上一篇: eclipse报错 eclipse启动报错解决方法
下一篇: 米旗蛋糕店加盟前景及口碑怎么样!