Parse file name from URL before downloading the file

后端 未结 6 1651
眼角桃花
眼角桃花 2020-12-24 01:18

I\'m downloading an ePub file from a URL.

Now I want to implement a mechanism by which if user tries to re-download the same file, he should get warning/error messag

6条回答
  •  Happy的楠姐
    2020-12-24 02:04

    I think using URL#getPath() should simplify things.

    public static String getFileNameFromUrl(URL url) {
    
        String urlPath = url.getPath();
    
        return urlPath.substring(urlPath.lastIndexOf('/') + 1);
    }
    

    See, http://developer.android.com/reference/java/net/URL.html#getPath()

提交回复
热议问题