public static boolean getfileType(String url){
if(null == url) return false;
if(TextUtils.isEmpty(url))return false;
String suffixes="pdf|jpg|png";
Pattern pat=Pattern.compile("[\\w]+[\\.]("+suffixes+")");//正则判断
Matcher mc=pat.matcher(url);//条件匹配
while(mc.find()){
return true;
}
return false;
}
public static String getFileType(String fileName){
if(null == fileName) return "";
if(TextUtils.isEmpty(fileName))return "";
return fileName.substring(fileName.lastIndexOf(".") + 1);//获取文件的后缀名;
}
String fileName="E:\\file.docx";
String temp[]=fileName.split("\\\\");
String fileNameNow=temp[temp.length-1];
System.out.println(fileNameNow);
//获取文件名
String filename = "file.docx";
String caselsh = filename.substring(0,filename.lastIndexOf("."));
System.out.println(caselsh);
String filename = "file.txt";// 文件名
String[] strArray = filename.split("\\.");
int suffixIndex = strArray.length -1;
System.out.println(strArray[suffixIndex]);
File file=new File("E:\\file.doc");
String fileName=file.getName();
String fileTyle=fileName.substring(fileName.lastIndexOf("."),fileName.length());
System.out.println(fileTyle);