get Url File Name - Android java.net

Android examples for java.net:URL

Description

get Url File Name

Demo Code

import android.util.Log;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{


    public static String getUrlFileName(String urlString) {
        String fileName = urlString.substring(urlString.lastIndexOf("/"));
        fileName = fileName.substring(1, fileName.length());
        if (fileName.equalsIgnoreCase("")) {
            Calendar c = Calendar.getInstance();
            fileName = c.get(Calendar.YEAR) + "" + c.get(Calendar.MONTH)
                    + "" + c.get(Calendar.DAY_OF_MONTH) + ""
                    + c.get(Calendar.MINUTE);

        }//from w ww.j  a v  a 2  s.  c  o  m
        return fileName;
    }

}

Related Tutorials