* 1:獲取文件後綴名
* 2:獲取版本號
* 3:獲取的字符串是否爲空
* @author Administrator
*
*/
public class VersionUtils {
//判斷對象是否爲空
public static String notNUll(String str) {
if (str==null||str==""||str.equals("")) {
return "";
}
return str;
}
//得到文件名.之後的後綴名
public static String getExtensionName(String fileName) {
if (fileName!=null&&fileName.length()>0) {
//獲取.所在的索引
int pointIndex = fileName.lastIndexOf(".");
if (pointIndex>-1&&(pointIndex<(fileName.length()-1))) {
//獲取後綴名
return fileName.substring(pointIndex+1);
}
}
return fileName;
}
//獲取文件版本號
public static String getVersion(String version) {
//獲取.之後的版本後綴名
String suffixValue = getExtensionName(version);
//獲取.之前的版本名稱
String preValue = version.substring(0, version.lastIndexOf("."));
Integer value = Integer.valueOf(suffixValue);
value++;
return preValue+"."+value;
}
public static void main(String[] args) {
String fileName="abc.txt";
String version="1.4.2";
String name = VersionUtils.getExtensionName(fileName);
System.out.println(name);
String version1 = VersionUtils.getVersion(version);
System.out.println(version);
String name2 = VersionUtils.getExtensionName(version);
System.err.println(name2);
}
}
測試結果