Quick Get URL file name and suffix name

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.