When downloading files from Android, it is always troublesome to judge the file name and suffix, we can get the file name and suffix name by the custom regular expression through the known URL path:
Custom MIME type:string suffixes= "Avi|mpeg|3gp|mp3|mp4|wav"//You can put all the file formats in the MIME source
String suffixes= "Avi|mpeg|3gp|mp3|mp4|wav|jpeg|gif|jpg|png|apk|exe|txt|html|htm|java|doc"; String file=url.substring (Url.lastindexof ('/') +1);//intercept URL last data Pattern pat=pattern.compile ("[\\w]+[\\.] ("+suffixes+");//Regular judgment Matcher mc=pat.matcher (file); while (Mc.find ()) {String substring = mc.group ();//intercept filename suffix name log.e ("substring:", substring);}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Quick Get URL file name and suffix name