当前位置: 编程技术>java/j2ee
java 文件名截取方法
来源: 互联网 发布时间:2014-10-22
本文导语: 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.截...
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;
}